abhicodes commited on
Commit
084d09d
1 Parent(s): 5a95868

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -45
app.py CHANGED
@@ -14,56 +14,39 @@ theme = gr.themes.Base(
14
 
15
  API_KEY = os.getenv("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 = {}
31
- print(response.json())
32
- for ele in response.json():
33
- label, score = ele.values()
34
- result[label] = score
35
-
36
- return result
37
 
38
 
39
  # Create a function to Detect/Classify Breast_Cancer
40
  def classify_breast_cancer(image):
41
- image_data = np.array(image, dtype=np.uint8)
42
- _, buffer = cv2.imencode('.jpg', image_data)
43
- binary_data = buffer.tobytes()
44
-
45
- response = requests.post(BREAST_CANCER_API_URL, headers=headers, data=binary_data)
46
- result = {}
47
- for ele in response:
48
- label, score = ele.values()
49
- result[label] = score
50
-
51
- return result
52
 
53
 
54
  # Create a function to Detect/Classify Brain_Tumor
55
  def classify_brain_tumor(image):
56
- image_data = np.array(image, dtype=np.uint8)
57
- _, buffer = cv2.imencode('.jpg', image_data)
58
- binary_data = buffer.tobytes()
59
-
60
- response = requests.post(BRAIN_TUMOR_API_URL, headers=headers, data=binary_data)
61
- result = {}
62
- for ele in response:
63
- label, score = ele.values()
64
- result[label] = score
65
-
66
- return result
67
 
68
 
69
  # Create the Gradio interface
@@ -85,8 +68,8 @@ with gr.Blocks(theme=theme) as Alzheimer:
85
 
86
  def respond(message, history):
87
  bot_message = g4f.ChatCompletion.create(
88
- model="gpt-4-32k-0613",
89
- provider=g4f.Provider.GeekGpt,
90
  messages=[{"role": "user",
91
  "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 simply avoid the query by saying this is not my expertise, whereas if related to Alzheimer reply it as usual. Here's the user Query:" + message}],
92
  )
@@ -120,8 +103,8 @@ with gr.Blocks(theme=theme) as BreastCancer:
120
 
121
  def respond(message, history):
122
  bot_message = g4f.ChatCompletion.create(
123
- model="gpt-4-32k-0613",
124
- provider=g4f.Provider.GeekGpt,
125
  messages=[{"role": "user",
126
  "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 simply avoid the query by saying this is not my expertise, whereas if related to Breast_Cancer reply it as usual. Here's the user Query:" + message}],
127
  )
@@ -154,8 +137,8 @@ with gr.Blocks(theme=theme) as BrainTumor:
154
 
155
  def respond(message, history):
156
  bot_message = g4f.ChatCompletion.create(
157
- model="gpt-4-32k-0613",
158
- provider=g4f.Provider.GeekGpt,
159
  messages=[{"role": "user",
160
  "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 simply avoid the query by saying this is not my expertise, whereas if related to Brain Tumor reply it as usual. Here's the user Query:" + message}],
161
  )
 
14
 
15
  API_KEY = os.getenv("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
+ alzheimer_classifier = pipeline("image-classification", model="AhmadHakami/alzheimer-image-classification-google-vit-base-patch16")
22
+ breast_cancer_classifier = pipeline("image-classification", model="MUmairAB/Breast_Cancer_Detector")
23
+ brain_tumor_classifier = pipeline("image-classification", model="Devarshi/Brain_Tumor_Classification")
24
 
25
  # Create a function to Detect/Classify Alzheimer
26
  def classify_alzheimer(image):
27
+ result = alzheimer_classifier(image)
28
+ prediction = result[0]
29
+ score = prediction['score']
30
+ label = prediction['label']
31
+ return {"score": score, "label": label}
 
 
 
 
 
 
 
32
 
33
 
34
  # Create a function to Detect/Classify Breast_Cancer
35
  def classify_breast_cancer(image):
36
+ result = breast_cancer_classifier(image)
37
+ prediction = result[0]
38
+ score = prediction['score']
39
+ label = prediction['label']
40
+ return {"score": score, "label": label}
 
 
 
 
 
 
41
 
42
 
43
  # Create a function to Detect/Classify Brain_Tumor
44
  def classify_brain_tumor(image):
45
+ result = brain_tumor_classifier(image)
46
+ prediction = result[0]
47
+ score = prediction['score']
48
+ label = prediction['label']
49
+ return {"score": score, "label": label}
 
 
 
 
 
 
50
 
51
 
52
  # Create the Gradio interface
 
68
 
69
  def respond(message, history):
70
  bot_message = g4f.ChatCompletion.create(
71
+ model="gpt-3.5-turbo",
72
+ provider=g4f.Provider.Vercel,
73
  messages=[{"role": "user",
74
  "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 simply avoid the query by saying this is not my expertise, whereas if related to Alzheimer reply it as usual. Here's the user Query:" + message}],
75
  )
 
103
 
104
  def respond(message, history):
105
  bot_message = g4f.ChatCompletion.create(
106
+ model="gpt-3.5-turbo",
107
+ provider=g4f.Provider.Vercel,
108
  messages=[{"role": "user",
109
  "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 simply avoid the query by saying this is not my expertise, whereas if related to Breast_Cancer reply it as usual. Here's the user Query:" + message}],
110
  )
 
137
 
138
  def respond(message, history):
139
  bot_message = g4f.ChatCompletion.create(
140
+ model="gpt-3.5-turbo",
141
+ provider=g4f.Provider.Vercel,
142
  messages=[{"role": "user",
143
  "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 simply avoid the query by saying this is not my expertise, whereas if related to Brain Tumor reply it as usual. Here's the user Query:" + message}],
144
  )