skjaini commited on
Commit
76acf42
·
verified ·
1 Parent(s): 2ee8b8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -11,7 +11,7 @@ def analyze_image_with_maira(image):
11
  """Analyzes the image using the Maira-2 model via the Hugging Face Inference API.
12
  """
13
  try:
14
- # Prepare image data - no need to encode for InferenceClient if sending bytes directly
15
  image_bytes = io.BytesIO()
16
  if image.mode == "RGBA": # Handle RGBA images (if any)
17
  image = image.convert("RGB")
@@ -19,11 +19,15 @@ 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.question_answering(
23
- question="Analyze this chest X-ray image and provide detailed findings. Include any abnormalities, their locations, and potential diagnoses. Be as specific as possible.",
24
- image=image_bytes, # Pass the image bytes directly
25
- model="microsoft/maira-2" # Specify the model
 
 
 
26
  )
 
27
  return result
28
 
29
  except Exception as e:
 
11
  """Analyzes the image using the Maira-2 model via the Hugging Face Inference API.
12
  """
13
  try:
14
+ # Prepare image data - send as bytes directly to 'inputs'
15
  image_bytes = io.BytesIO()
16
  if image.mode == "RGBA": # Handle RGBA images (if any)
17
  image = image.convert("RGB")
 
19
  image_bytes = image_bytes.getvalue() # Get the bytes
20
 
21
  client = InferenceClient() # No token needed inside the Space
22
+ result = client.run(
23
+ task="visual-question-answering", # Explicitly specify the task
24
+ model="microsoft/maira-2", # Specify the model
25
+ inputs={
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: