datdevsteve commited on
Commit
fc72ccd
·
verified ·
1 Parent(s): 13967c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -1,5 +1,8 @@
1
  import gradio as gr
2
-
 
 
 
3
  from nivra_agent import nivra_chat, nivra_vision
4
  from indicTrans3Infer import translate_text
5
 
@@ -16,8 +19,19 @@ def chat_fn(message, history):
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)
 
1
  import gradio as gr
2
+ import tempfile
3
+ import uuid
4
+ import os
5
+ import base64
6
  from nivra_agent import nivra_chat, nivra_vision
7
  from indicTrans3Infer import translate_text
8
 
 
19
  # ===============================
20
  # Translation endpoint
21
  # ===============================
22
+ UPLOAD_DIR = "/tmp/uploads"
23
+ os.makedirs(UPLOAD_DIR, exist_ok=True)
24
+
25
+ def upload_image(image_base64: str):
26
+ img_bytes = base64.b64decode(image_base64)
27
+ filename = f"{uuid.uuid4()}.png"
28
+ path = os.path.join(UPLOAD_DIR, filename)
29
+
30
+ with open(path, "wb") as f:
31
+ f.write(img_bytes)
32
+
33
+ # Expose via HF Space static file serving
34
+ return f"{os.environ['SPACE_HOST']}/file={path}"
35
 
36
  # ===============================
37
  # 🆕 Vision endpoint (CRITICAL FIX)