abhicodes commited on
Commit
b59c607
1 Parent(s): 693935b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -16
app.py CHANGED
@@ -17,7 +17,7 @@ API_KEY = os.getenv("API_KEY")
17
  BRAIN_TUMOR_API_URL = "https://api-inference.huggingface.co/models/Devarshi/Brain_Tumor_Classification"
18
  BREAST_CANCER_API_URL = "https://api-inference.huggingface.co/models/MUmairAB/Breast_Cancer_Detector"
19
  ALZHEIMER_API_URL = "https://api-inference.huggingface.co/models/AhmadHakami/alzheimer-image-classification-google-vit-base-patch16"
20
- headers = {"Authorization": "Bearer "+ API_KEY+"", 'Content-Type': 'application/json'}
21
 
22
 
23
  # Create a function to Detect/Classify Alzheimer
@@ -32,7 +32,7 @@ def classify_alzheimer(image):
32
  return result
33
 
34
 
35
- # Create a function to Detect/Classify Breast Cancer
36
  def classify_breast_cancer(image):
37
  image_data = np.array(image, dtype=np.uint8)
38
  _, buffer = cv2.imencode('.jpg', image_data)
@@ -44,7 +44,7 @@ def classify_breast_cancer(image):
44
  return result
45
 
46
 
47
- # Create a function to Detect/Classify Brain Tumor
48
  def classify_brain_tumor(image):
49
  image_data = np.array(image, dtype=np.uint8)
50
  _, buffer = cv2.imencode('.jpg', image_data)
@@ -65,15 +65,18 @@ with gr.Blocks(theme=theme) as Alzheimer:
65
  image = gr.Image()
66
  output = gr.Label(label='Alzheimer Classification', container=True, scale=2)
67
  with gr.Row():
68
- button = gr.Button(value="Submit", variant="primary")
69
  gr.ClearButton([image, output])
 
 
 
 
70
 
71
  button.click(classify_alzheimer, [image], [output])
72
 
73
  def respond(message, history):
74
  bot_message = g4f.ChatCompletion.create(
75
  model="gpt-3.5-turbo",
76
- provider=g4f.Provider.GptGo,
77
  messages=[{"role": "user",
78
  "content": "Your role is Alzheimer Disease Expert. Now I will provide you with the user query. First check if the user query is related to Alzheimer or not. If it is not related to Alzheimer then do not reply the query whereas if related to Alzheimer reply it as usual. Here's the user Query:" + message}],
79
  )
@@ -84,7 +87,7 @@ with gr.Blocks(theme=theme) as Alzheimer:
84
  with gr.Column():
85
  gr.Markdown("# Health Bot for Alzheimer")
86
  gr.Markdown("> **Note:** The information may not be accurate. Please consult a Doctor before considering any actions.")
87
- gr.ChatInterface(respond, autofocus=False).queue()
88
 
89
 
90
  with gr.Blocks(theme=theme) as BreastCancer:
@@ -95,25 +98,30 @@ with gr.Blocks(theme=theme) as BreastCancer:
95
  image = gr.Image()
96
  output = gr.Label(label='Breast Cancer Classification', container=True, scale=2)
97
  with gr.Row():
98
- button = gr.Button(value="Classify")
99
  gr.ClearButton([image, output])
 
 
 
 
 
100
 
101
  button.click(classify_breast_cancer, [image], [output])
102
 
103
  def respond(message, history):
104
  bot_message = g4f.ChatCompletion.create(
105
  model="gpt-3.5-turbo",
106
- provider=g4f.Provider.GptGo,
107
  messages=[{"role": "user",
108
- "content": "Your role is Breast Cancer Disease Expert. Now I will provide you with the user query. First check if the user query is related to Breast Cancer or not. If it is not related to Breast Cancer then do not reply the query whereas if related to Breast Cancer reply it as usual. Here's the user Query:" + message}],
109
  )
110
  time.sleep(1)
111
- return str(bot_message)
112
 
113
  with gr.Column():
114
  gr.Markdown("# Health Bot for Breast Cancer")
115
  gr.Markdown("> **Note:** The information may not be accurate. Please consult a Doctor before considering any actions.")
116
- gr.ChatInterface(respond, autofocus=False).queue()
117
 
118
 
119
  with gr.Blocks(theme=theme) as BrainTumor:
@@ -122,10 +130,15 @@ with gr.Blocks(theme=theme) as BrainTumor:
122
  gr.Markdown("# Brain Tumor Detection and Classification")
123
  gr.Markdown("> Classify the Brain Tumor.")
124
  image = gr.Image()
125
- output = gr.Label(label='Brain Tumor Classification', container=True, scale=2)
126
  with gr.Row():
127
- button = gr.Button(value="Classify")
128
  gr.ClearButton([image, output])
 
 
 
 
 
129
 
130
  button.click(classify_brain_tumor, [image], [output])
131
 
@@ -142,11 +155,11 @@ with gr.Blocks(theme=theme) as BrainTumor:
142
  with gr.Column():
143
  gr.Markdown("# Health Bot for Brain Tumor")
144
  gr.Markdown("> **Note:** The information may not be accurate. Please consult a Doctor before considering any actions.")
145
- gr.ChatInterface(respond, autofocus=False, examples=["Explain Brain Tumor."]).queue()
146
 
147
 
148
  Main = gr.TabbedInterface([Alzheimer, BreastCancer, BrainTumor], ["Alzheimer", "Breast Cancer", "Brain Tumor"],
149
  theme=theme,
150
- css=".gradio-container { background: rgba(255, 255, 255, 0.2) !important; box-shadow: 0 8px 32px 0 rgba( 31, 38, 135, 0.37 ) !important !important; backdrop-filter: blur( 10px ) !important; -webkit-backdrop-filter: blur( 10px ) !important; border-radius: 10px !important; border: 1px solid rgba( 255, 255, 255, 0.18 ) !important;}")
151
 
152
- Main.launch()
 
17
  BRAIN_TUMOR_API_URL = "https://api-inference.huggingface.co/models/Devarshi/Brain_Tumor_Classification"
18
  BREAST_CANCER_API_URL = "https://api-inference.huggingface.co/models/MUmairAB/Breast_Cancer_Detector"
19
  ALZHEIMER_API_URL = "https://api-inference.huggingface.co/models/AhmadHakami/alzheimer-image-classification-google-vit-base-patch16"
20
+ headers = {"Authorization": "Bearer "+API_KEY+"", 'Content-Type': 'application/json'}
21
 
22
 
23
  # Create a function to Detect/Classify Alzheimer
 
32
  return result
33
 
34
 
35
+ # Create a function to Detect/Classify Breast_Cancer
36
  def classify_breast_cancer(image):
37
  image_data = np.array(image, dtype=np.uint8)
38
  _, buffer = cv2.imencode('.jpg', image_data)
 
44
  return result
45
 
46
 
47
+ # Create a function to Detect/Classify Brain_Tumor
48
  def classify_brain_tumor(image):
49
  image_data = np.array(image, dtype=np.uint8)
50
  _, buffer = cv2.imencode('.jpg', image_data)
 
65
  image = gr.Image()
66
  output = gr.Label(label='Alzheimer Classification', container=True, scale=2)
67
  with gr.Row():
 
68
  gr.ClearButton([image, output])
69
+ button = gr.Button(value="Submit", variant="primary")
70
+ gr.Examples(inputs=image, fn=classify_alzheimer, examples=[os.path.join(os.path.dirname(__file__), "diseases/Alzheimer/mild_12.jpg"),
71
+ os.path.join(os.path.dirname(__file__), "diseases/Alzheimer/moderate_21.jpg"),
72
+ os.path.join(os.path.dirname(__file__), "diseases/Alzheimer/verymild_1013.jpg")])
73
 
74
  button.click(classify_alzheimer, [image], [output])
75
 
76
  def respond(message, history):
77
  bot_message = g4f.ChatCompletion.create(
78
  model="gpt-3.5-turbo",
79
+ provider=g4f.Provider.You,
80
  messages=[{"role": "user",
81
  "content": "Your role is Alzheimer Disease Expert. Now I will provide you with the user query. First check if the user query is related to Alzheimer or not. If it is not related to Alzheimer then do not reply the query whereas if related to Alzheimer reply it as usual. Here's the user Query:" + message}],
82
  )
 
87
  with gr.Column():
88
  gr.Markdown("# Health Bot for Alzheimer")
89
  gr.Markdown("> **Note:** The information may not be accurate. Please consult a Doctor before considering any actions.")
90
+ gr.ChatInterface(respond, autofocus=False, examples=["Explain Alzhiemer diasease.", "What are the types of Alzhiemer diasease?", "Alzhiemer Prevention methods."]).queue()
91
 
92
 
93
  with gr.Blocks(theme=theme) as BreastCancer:
 
98
  image = gr.Image()
99
  output = gr.Label(label='Breast Cancer Classification', container=True, scale=2)
100
  with gr.Row():
101
+ button = gr.Button(value="Submit", variant="primary")
102
  gr.ClearButton([image, output])
103
+ gr.Examples(inputs=image, fn=classify_breast_cancer,
104
+ examples=[os.path.join(os.path.dirname(__file__), "diseases/Breast_Cancer/class0.png"),
105
+ os.path.join(os.path.dirname(__file__), "diseases/Breast_Cancer/class0_1.png"),
106
+ os.path.join(os.path.dirname(__file__), "diseases/Breast_Cancer/class1.png"),
107
+ os.path.join(os.path.dirname(__file__), "diseases/Breast_Cancer/class1_1.png")])
108
 
109
  button.click(classify_breast_cancer, [image], [output])
110
 
111
  def respond(message, history):
112
  bot_message = g4f.ChatCompletion.create(
113
  model="gpt-3.5-turbo",
114
+ provider=g4f.Provider.You,
115
  messages=[{"role": "user",
116
+ "content": "Your role is Breast_Cancer Disease Expert. Now I will provide you with the user query. First check if the user query is related to Breast_Cancer or not. If it is not related to Breast_Cancer then do not reply the query whereas if related to Breast_Cancer reply it as usual. Here's the user Query:" + message}],
117
  )
118
  time.sleep(1)
119
+ yield str(bot_message)
120
 
121
  with gr.Column():
122
  gr.Markdown("# Health Bot for Breast Cancer")
123
  gr.Markdown("> **Note:** The information may not be accurate. Please consult a Doctor before considering any actions.")
124
+ gr.ChatInterface(respond, autofocus=False, examples=["Explain Breast Cancer.", "What are the types of Breast Cancer?", "Breast Cancer Prevention methods."]).queue()
125
 
126
 
127
  with gr.Blocks(theme=theme) as BrainTumor:
 
130
  gr.Markdown("# Brain Tumor Detection and Classification")
131
  gr.Markdown("> Classify the Brain Tumor.")
132
  image = gr.Image()
133
+ output = gr.Label(label='Brain_Tumor Classification', container=True, scale=2)
134
  with gr.Row():
135
+ button = gr.Button(value="Submit", variant="primary")
136
  gr.ClearButton([image, output])
137
+ gr.Examples(inputs=image, fn=classify_brain_tumor,
138
+ examples=[os.path.join(os.path.dirname(__file__), "diseases/Brain_Tumor/glioma.jpg"),
139
+ os.path.join(os.path.dirname(__file__), "diseases/Brain_Tumor/meningioma.jpg"),
140
+ os.path.join(os.path.dirname(__file__), "diseases/Brain_Tumor/no_tumor.jpg"),
141
+ os.path.join(os.path.dirname(__file__), "diseases/Brain_Tumor/pituitary.jpg")])
142
 
143
  button.click(classify_brain_tumor, [image], [output])
144
 
 
155
  with gr.Column():
156
  gr.Markdown("# Health Bot for Brain Tumor")
157
  gr.Markdown("> **Note:** The information may not be accurate. Please consult a Doctor before considering any actions.")
158
+ gr.ChatInterface(respond, autofocus=False, examples=["Explain Brain Tumor.", "What are the types of Brain Tumor?", "Brain Tumor Prevention methods."]).queue()
159
 
160
 
161
  Main = gr.TabbedInterface([Alzheimer, BreastCancer, BrainTumor], ["Alzheimer", "Breast Cancer", "Brain Tumor"],
162
  theme=theme,
163
+ css=".gradio-container { background: rgba(255, 255, 255, 0.2) !important; box-shadow: 0 8px 32px 0 rgba( 31, 38, 135, 0.37 ) !important; backdrop-filter: blur( 10px ) !important; -webkit-backdrop-filter: blur( 10px ) !important; border-radius: 10px !important; border: 1px solid rgba( 0, 0, 0, 0.5 ) !important;}")
164
 
165
+ Main.launch()