abhicodes commited on
Commit
d765024
1 Parent(s): 4fafef8

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +152 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+ import requests
5
+ import g4f
6
+ import time
7
+ import os
8
+
9
+ theme = gr.themes.Base(
10
+ primary_hue="cyan",
11
+ secondary_hue="blue",
12
+ neutral_hue="slate",
13
+ )
14
+
15
+ API_KEY = os.environ.get("API_KEY")
16
+
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
24
+ def classify_alzheimer(image):
25
+ image_data = np.array(image, dtype=np.uint8)
26
+ _, buffer = cv2.imencode('.jpg', image_data)
27
+ binary_data = buffer.tobytes()
28
+
29
+ response = requests.post(ALZHEIMER_API_URL, headers=headers, data=binary_data)
30
+ result = {item['label']: item['score'] for item in response.json()}
31
+
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)
39
+ binary_data = buffer.tobytes()
40
+
41
+ response = requests.post(BREAST_CANCER_API_URL, headers=headers, data=binary_data)
42
+ result = {item['label']: item['score'] for item in response.json()}
43
+
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)
51
+ binary_data = buffer.tobytes()
52
+
53
+ response = requests.post(BRAIN_TUMOR_API_URL, headers=headers, data=binary_data)
54
+ result = {item['label']: item['score'] for item in response.json()}
55
+
56
+ return result
57
+
58
+
59
+ # Create the Gradio interface
60
+ with gr.Blocks(theme=theme) as Alzheimer:
61
+ with gr.Row():
62
+ with gr.Column():
63
+ gr.Markdown("# Alzheimer Detection and Classification")
64
+ gr.Markdown("> Classify the alzheimer into Mild Demented, Very Mild Demented, Moderate Demented and Non Demented.")
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
+ )
80
+ time.sleep(1)
81
+ yield str(bot_message)
82
+
83
+
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:
91
+ with gr.Row():
92
+ with gr.Column():
93
+ gr.Markdown("# Breast Cancer Detection and Classification")
94
+ gr.Markdown("> Classify the breast cancer.")
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
+ yield 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:
120
+ with gr.Row():
121
+ with gr.Column():
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
+
132
+ def respond(message, history):
133
+ bot_message = g4f.ChatCompletion.create(
134
+ model="gpt-3.5-turbo",
135
+ provider=g4f.Provider.GptGo,
136
+ messages=[{"role": "user",
137
+ "content": "Your role is Brain Tumor Disease Expert. Now I will provide you with the user query. First check if the user query is related to Brain Tumor or not. If it is not related to Brain Tumor then do not reply the query whereas if related to Brain Tumor reply it as usual. Here's the user Query:" + message}],
138
+ )
139
+ time.sleep(1)
140
+ yield str(bot_message)
141
+
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()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ opencv-python
3
+ numpy