Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import os | |
| HF_URL = "http://localhost:7860/completion" # llama-server inside container | |
| def translate(text, direction): | |
| if direction == "English β Japanese": | |
| prompt = f"Translate to Japanese:\n{text}\nJapanese:" | |
| else: | |
| prompt = f"Translate to English:\n{text}\nEnglish:" | |
| resp = requests.post( | |
| HF_URL, | |
| json={ | |
| "prompt": prompt, | |
| "n_predict": 128, | |
| "temperature": 0.1, | |
| "top_p": 0.9, | |
| "repeat_penalty": 1.3, | |
| "stop": ["\n\n","</s>"] | |
| } | |
| ) | |
| return resp.json().get("content", "") | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# π¬π§βπ―π΅ English β Japanese Translator (llama.cpp)") | |
| with gr.Row(): | |
| with gr.Column(): | |
| direction = gr.Radio(["English β Japanese", "Japanese β English"], value="English β Japanese") | |
| input_box = gr.Textbox(label="Input") | |
| output_box = gr.Textbox(label="Translation") | |
| run_btn = gr.Button("Translate") | |
| run_btn.click(fn=translate, inputs=[input_box, direction], outputs=output_box) | |
| demo.launch(server_name="0.0.0.0", server_port=7860) |