datdevsteve commited on
Commit
3af6e4e
·
verified ·
1 Parent(s): 7d314da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -20
app.py CHANGED
@@ -1,11 +1,11 @@
1
  import gradio as gr
 
2
  from nivra_agent import nivra_chat, nivra_vision
3
  from indicTrans3Infer import translate_text
4
 
5
  # ===============================
6
  # Chat endpoint
7
  # ===============================
8
-
9
  def chat_fn(message, history):
10
  history = history or []
11
  history.append({"role": "user", "content": message})
@@ -16,24 +16,25 @@ def chat_fn(message, history):
16
  # ===============================
17
  # Translation endpoint
18
  # ===============================
19
-
20
  def indictrans_translate(text: str, target_language: str):
21
  return translate_text(text, target_language)
22
 
23
  # ===============================
24
- # 🆕 Vision endpoint
25
  # ===============================
26
-
27
  def vision_fn(image_base64: str, hint_text: str):
 
28
  return nivra_vision(image_base64, hint_text)
29
 
30
  # ===============================
31
- # UI
32
  # ===============================
33
-
34
  with gr.Blocks(title="🩺 Nivra AI Agent") as demo:
35
  gr.Markdown("# 🩺 Nivra AI Agent")
36
 
 
 
 
37
  chatbot = gr.Chatbot(show_label=False)
38
  txt = gr.Textbox(placeholder="Describe your symptoms...")
39
  send = gr.Button("Send")
@@ -41,21 +42,35 @@ with gr.Blocks(title="🩺 Nivra AI Agent") as demo:
41
  send.click(chat_fn, inputs=[txt, chatbot], outputs=[chatbot, txt])
42
  txt.submit(chat_fn, inputs=[txt, chatbot], outputs=[chatbot, txt])
43
 
44
- # Hidden API endpoints
45
- gr.Button(visible=False).click(
46
- indictrans_translate,
47
- inputs=[gr.Textbox(), gr.Textbox()],
48
- outputs=[gr.Textbox()],
49
- api_name="indictrans_translate",
50
- )
51
-
52
- gr.Button(visible=False).click(
53
- vision_fn,
54
- inputs=[gr.Textbox(), gr.Textbox()],
55
- outputs=[gr.Textbox()],
56
- api_name="vision_fn",
57
- )
 
 
 
 
 
 
 
 
 
 
 
 
58
 
 
 
59
  demo.launch(
60
  server_name="0.0.0.0",
61
  server_port=7860,
 
1
  import gradio as gr
2
+
3
  from nivra_agent import nivra_chat, nivra_vision
4
  from indicTrans3Infer import translate_text
5
 
6
  # ===============================
7
  # Chat endpoint
8
  # ===============================
 
9
  def chat_fn(message, history):
10
  history = history or []
11
  history.append({"role": "user", "content": message})
 
16
  # ===============================
17
  # Translation endpoint
18
  # ===============================
 
19
  def indictrans_translate(text: str, target_language: str):
20
  return translate_text(text, target_language)
21
 
22
  # ===============================
23
+ # 🆕 Vision endpoint (CRITICAL FIX)
24
  # ===============================
 
25
  def vision_fn(image_base64: str, hint_text: str):
26
+ # IMPORTANT: return STRING ONLY
27
  return nivra_vision(image_base64, hint_text)
28
 
29
  # ===============================
30
+ # UI + API
31
  # ===============================
 
32
  with gr.Blocks(title="🩺 Nivra AI Agent") as demo:
33
  gr.Markdown("# 🩺 Nivra AI Agent")
34
 
35
+ # -------------------------------
36
+ # Chat UI
37
+ # -------------------------------
38
  chatbot = gr.Chatbot(show_label=False)
39
  txt = gr.Textbox(placeholder="Describe your symptoms...")
40
  send = gr.Button("Send")
 
42
  send.click(chat_fn, inputs=[txt, chatbot], outputs=[chatbot, txt])
43
  txt.submit(chat_fn, inputs=[txt, chatbot], outputs=[chatbot, txt])
44
 
45
+ # -------------------------------
46
+ # Hidden API endpoints (ISOLATED)
47
+ # -------------------------------
48
+ with gr.Row(visible=False):
49
+ translate_in = gr.Textbox()
50
+ translate_lang = gr.Textbox()
51
+ translate_out = gr.Textbox()
52
+
53
+ gr.Button().click(
54
+ indictrans_translate,
55
+ inputs=[translate_in, translate_lang],
56
+ outputs=[translate_out],
57
+ api_name="indictrans_translate",
58
+ )
59
+
60
+ with gr.Row(visible=False):
61
+ vision_image = gr.Textbox()
62
+ vision_hint = gr.Textbox()
63
+ vision_out = gr.Textbox()
64
+
65
+ gr.Button().click(
66
+ vision_fn,
67
+ inputs=[vision_image, vision_hint],
68
+ outputs=[vision_out],
69
+ api_name="vision_fn",
70
+ )
71
 
72
+ # 🔑 QUEUE DISABLED — REQUIRED FOR IMAGE SSE
73
+ demo.queue(concurrency_count=1, max_size=5)
74
  demo.launch(
75
  server_name="0.0.0.0",
76
  server_port=7860,