Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,16 +40,20 @@ UPLOAD_DIR = "/tmp/uploads"
|
|
| 40 |
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 41 |
|
| 42 |
def vision_fn(image, hint_text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
filename = f"{uuid.uuid4()}.png"
|
| 44 |
path = os.path.join(UPLOAD_DIR, filename)
|
| 45 |
|
| 46 |
image.save(path)
|
| 47 |
|
| 48 |
-
# HF exposes files automatically via /file=
|
| 49 |
image_url = f"https://datdevsteve-nivra-ai-agent.hf.space/file={path}"
|
| 50 |
-
|
| 51 |
return nivra_vision(image_url, hint_text)
|
| 52 |
|
|
|
|
| 53 |
# ===============================
|
| 54 |
# UI + API
|
| 55 |
# ===============================
|
|
@@ -82,11 +86,13 @@ with gr.Blocks(title="🩺 Nivra AI Agent") as demo:
|
|
| 82 |
|
| 83 |
gr.Button(visible=False).click(
|
| 84 |
vision_fn,
|
| 85 |
-
inputs=[
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
| 90 |
|
| 91 |
# 🔴 DO NOT enable queue for Flutter SSE
|
| 92 |
demo.launch(
|
|
|
|
| 40 |
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 41 |
|
| 42 |
def vision_fn(image, hint_text):
|
| 43 |
+
import uuid, os
|
| 44 |
+
|
| 45 |
+
UPLOAD_DIR = "/tmp/uploads"
|
| 46 |
+
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 47 |
+
|
| 48 |
filename = f"{uuid.uuid4()}.png"
|
| 49 |
path = os.path.join(UPLOAD_DIR, filename)
|
| 50 |
|
| 51 |
image.save(path)
|
| 52 |
|
|
|
|
| 53 |
image_url = f"https://datdevsteve-nivra-ai-agent.hf.space/file={path}"
|
|
|
|
| 54 |
return nivra_vision(image_url, hint_text)
|
| 55 |
|
| 56 |
+
|
| 57 |
# ===============================
|
| 58 |
# UI + API
|
| 59 |
# ===============================
|
|
|
|
| 86 |
|
| 87 |
gr.Button(visible=False).click(
|
| 88 |
vision_fn,
|
| 89 |
+
inputs=[
|
| 90 |
+
gr.Image(type="pil", label="Medical Image"),
|
| 91 |
+
gr.Textbox(label="Optional description"),
|
| 92 |
+
],
|
| 93 |
+
outputs=[gr.Textbox()],
|
| 94 |
+
api_name="vision_fn",
|
| 95 |
+
)
|
| 96 |
|
| 97 |
# 🔴 DO NOT enable queue for Flutter SSE
|
| 98 |
demo.launch(
|