MahatirTusher commited on
Commit
d052fbd
·
verified ·
1 Parent(s): 8170a5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -10
app.py CHANGED
@@ -7,10 +7,29 @@ from datasets import load_dataset, DownloadConfig
7
  import matplotlib.pyplot as plt
8
  import numpy as np
9
  import cv2
10
- from groq import Groq
11
 
12
- # Initialize Groq client
13
- client = Groq(api_key="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")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  # Model and processor configuration
16
  model_name_or_path = "google/vit-base-patch16-224-in21k"
@@ -47,13 +66,7 @@ def get_ai_explanation(diagnosis, probabilities):
47
  4. Mention warning signs to watch for
48
  Keep the tone informative and caring but emphasize the importance of professional medical consultation."""
49
 
50
- completion = client.chat.completions.create(
51
- messages=[{"role": "user", "content": prompt}],
52
- model="mixtral-8x7b-32768",
53
- temperature=0.7,
54
- )
55
-
56
- return completion.choices[0].message.content
57
 
58
  def classify_and_visualize(img, device="cpu", discard_ratio=0.9, head_fusion="mean"):
59
  img = img.convert("RGB")
 
7
  import matplotlib.pyplot as plt
8
  import numpy as np
9
  import cv2
10
+ import requests
11
 
12
+ # Mistral AI API configuration
13
+ MISTRAL_API_KEY = "eoiBrPQzLjwNgOFgD7I4A4XF3TJOgBet"
14
+ MISTRAL_API_URL = "https://api.mistral.ai/v1/chat/completions"
15
+
16
+ def get_mistral_completion(prompt):
17
+ headers = {
18
+ "Content-Type": "application/json",
19
+ "Authorization": f"Bearer {MISTRAL_API_KEY}"
20
+ }
21
+
22
+ data = {
23
+ "model": "mistral-medium",
24
+ "messages": [{"role": "user", "content": prompt}],
25
+ "temperature": 0.7
26
+ }
27
+
28
+ response = requests.post(MISTRAL_API_URL, headers=headers, json=data)
29
+ if response.status_code == 200:
30
+ return response.json()['choices'][0]['message']['content']
31
+ else:
32
+ return "Error getting AI explanation. Please try again."
33
 
34
  # Model and processor configuration
35
  model_name_or_path = "google/vit-base-patch16-224-in21k"
 
66
  4. Mention warning signs to watch for
67
  Keep the tone informative and caring but emphasize the importance of professional medical consultation."""
68
 
69
+ return get_mistral_completion(prompt)
 
 
 
 
 
 
70
 
71
  def classify_and_visualize(img, device="cpu", discard_ratio=0.9, head_fusion="mean"):
72
  img = img.convert("RGB")