File size: 2,315 Bytes
fc72ccd
7b86135
 
 
7723208
7b86135
a128dff
7b86135
 
 
728c786
fc72ccd
 
 
7b86135
 
 
 
fc72ccd
7b86135
 
 
409de94
7b86135
 
 
728c786
7b86135
7498b9a
7b86135
 
7498b9a
7b86135
 
 
 
 
91d3362
7b86135
7498b9a
7b86135
3af6e4e
7b86135
 
f3a4765
7b86135
 
 
 
50d392b
3af6e4e
 
 
f3a4765
7b86135
 
 
f3a4765
a128dff
 
 
7b86135
3af6e4e
7b86135
3af6e4e
7b86135
 
 
08b7321
 
7498b9a
 
 
7b86135
 
 
 
afae4f8
a128dff
 
 
f3a4765
12788e5
a128dff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
import uuid
import gradio as gr
from PIL import Image

from nivra_agent import nivra_chat, nivra_vision

# ==================================================
# Constants
# ==================================================

UPLOAD_DIR = "/tmp/uploads"
os.makedirs(UPLOAD_DIR, exist_ok=True)

SPACE_HOST = os.environ.get(
    "SPACE_HOST",
    "https://datdevsteve-nivra-ai-agent.hf.space"
)

# ==================================================
# CHAT ENDPOINT
# ==================================================

def chat_fn(message, history):
    history = history or []
    history.append({"role": "user", "content": message})

    response = nivra_chat(message, history)

    history.append({"role": "assistant", "content": response})
    return history, ""

# ==================================================
# 🆕 VISION ENDPOINT (FILE-BASED, NO BASE64)
# ==================================================


def vision_fn(image_url: str, hint_text: str):
    return nivra_vision(image_url, hint_text)

# ==================================================
# UI + API
# ==================================================

with gr.Blocks(title="🩺 Nivra AI Agent") as demo:
    gr.Markdown(
        "# 🩺 Nivra AI Agent\n"
        "_AI-powered healthcare assistant for preliminary guidance._"
    )

    # -------------------------------
    # Chat UI
    # -------------------------------
    chatbot = gr.Chatbot(show_label=False)
    txt = gr.Textbox(
        placeholder="Describe your symptoms (e.g. fever, headache, rash)..."
    )
    send = gr.Button("Send")

    send.click(chat_fn, inputs=[txt, chatbot], outputs=[chatbot, txt])
    txt.submit(chat_fn, inputs=[txt, chatbot], outputs=[chatbot, txt])

    # -------------------------------
    # 🔒 Hidden Vision API (Flutter)
    # -------------------------------
    gr.Button(visible=False).click(
        vision_fn,
        inputs=[
            gr.Textbox(label="image_url"),
            gr.Textbox(label="hint_text"),
        ],
        outputs=[gr.Textbox()],
        api_name="vision_fn",
    )
# ==================================================
# Launch (HF-safe)
# ==================================================

demo.launch(
    server_name="0.0.0.0",
    server_port=7860,
    ssr_mode=False,
    show_error=True
)