Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,10 +3,6 @@ from PIL import Image
|
|
3 |
from huggingface_hub import InferenceClient
|
4 |
import io
|
5 |
|
6 |
-
# --- Configuration (Simplified for Spaces) ---
|
7 |
-
|
8 |
-
# --- Model Interaction (using InferenceClient) ---
|
9 |
-
|
10 |
def analyze_image_with_maira(image):
|
11 |
"""Analyzes the image using the Maira-2 model via the Hugging Face Inference API.
|
12 |
"""
|
@@ -19,15 +15,16 @@ def analyze_image_with_maira(image):
|
|
19 |
image_bytes = image_bytes.getvalue() # Get the bytes
|
20 |
|
21 |
client = InferenceClient() # No token needed inside the Space
|
22 |
-
result = client.
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
24 |
model="microsoft/maira-2", # Specify the model
|
25 |
-
|
26 |
-
"image": image_bytes,
|
27 |
-
"question": "Analyze this chest X-ray image and provide detailed findings. Include any abnormalities, their locations, and potential diagnoses. Be as specific as possible.",
|
28 |
-
}
|
29 |
)
|
30 |
-
|
31 |
return result
|
32 |
|
33 |
except Exception as e:
|
|
|
3 |
from huggingface_hub import InferenceClient
|
4 |
import io
|
5 |
|
|
|
|
|
|
|
|
|
6 |
def analyze_image_with_maira(image):
|
7 |
"""Analyzes the image using the Maira-2 model via the Hugging Face Inference API.
|
8 |
"""
|
|
|
15 |
image_bytes = image_bytes.getvalue() # Get the bytes
|
16 |
|
17 |
client = InferenceClient() # No token needed inside the Space
|
18 |
+
result = client.post(
|
19 |
+
json={
|
20 |
+
"inputs": {
|
21 |
+
"image": image_bytes.decode(encoding="latin-1"), #Needs to be decoded
|
22 |
+
"question": "Analyze this chest X-ray image and provide detailed findings. Include any abnormalities, their locations, and potential diagnoses. Be as specific as possible.",
|
23 |
+
}
|
24 |
+
},
|
25 |
model="microsoft/maira-2", # Specify the model
|
26 |
+
task="visual-question-answering"
|
|
|
|
|
|
|
27 |
)
|
|
|
28 |
return result
|
29 |
|
30 |
except Exception as e:
|