Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,45 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
| 3 |
from gradio_client import Client
|
|
|
|
|
|
|
|
|
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
def
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
client = Client("Chatboong/Gemini_Translator") # working as of 20251125,
|
| 10 |
result = client.predict(
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
)
|
| 16 |
return result
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
demo.load(
|
| 36 |
-
fn=chat,
|
| 37 |
-
inputs=gr.Textbox(),
|
| 38 |
-
outputs=gr.Textbox(),
|
| 39 |
-
api_name="/chat"
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from fastapi import FastAPI
|
| 3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
from gradio_client import Client
|
| 5 |
+
import uvicorn
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
|
| 9 |
+
# Enable CORS
|
| 10 |
+
app.add_middleware(
|
| 11 |
+
CORSMiddleware,
|
| 12 |
+
allow_origins=["*"], # or restrict to specific domains
|
| 13 |
+
allow_credentials=True,
|
| 14 |
+
allow_methods=["*"],
|
| 15 |
+
allow_headers=["*"],
|
| 16 |
+
)
|
| 17 |
|
| 18 |
+
def translate_zomi(text: str):
|
| 19 |
+
msg = f"Translate Zomi to English: '{text}'"
|
| 20 |
+
client = Client("Chatboong/Gemini_Translator")
|
|
|
|
| 21 |
result = client.predict(
|
| 22 |
+
message=msg,
|
| 23 |
+
lang="English",
|
| 24 |
+
is_streaming=True,
|
| 25 |
+
api_name="/chat"
|
| 26 |
)
|
| 27 |
return result
|
| 28 |
+
|
| 29 |
+
@app.post("/chat")
|
| 30 |
+
async def chat_api(message: str):
|
| 31 |
+
return {"translation": translate_zomi(message)}
|
| 32 |
+
|
| 33 |
+
def chat_ui(message):
|
| 34 |
+
return translate_zomi(message)
|
| 35 |
+
|
| 36 |
+
with gr.Blocks() as demo:
|
| 37 |
+
gr.Markdown("### Zomi Translator")
|
| 38 |
+
inp = gr.Textbox(label="Input")
|
| 39 |
+
out = gr.Textbox(label="Output")
|
| 40 |
+
inp.submit(chat_ui, inp, out)
|
| 41 |
+
|
| 42 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|