Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|