Spaces:
Sleeping
Sleeping
Download app.py from milan-mt/localization-test: direct link, hf CLI and curl.
- Browser
- Download file 873 Bytes
-
https://huggingface.co/spaces/milan-mt/localization-test/resolve/main/app.py
- Command line
-
hf download hf://spaces/milan-mt/localization-test/app.py
-
curl -L -o app.py https://huggingface.co/spaces/milan-mt/localization-test/resolve/main/app.py
873 Bytes
| import gradio as gr | |
| import requests | |
| import os | |
| API_URL = "https://mtf-localization-api.azurewebsites.net/translate" | |
| API_KEY = os.getenv("API_KEY") | |
| def translate_text(text, target_lang): | |
| try: | |
| headers = {} | |
| if API_KEY: | |
| headers["Authorization"] = f"Bearer {API_KEY}" | |
| response = requests.post( | |
| API_URL, | |
| json={ | |
| "text": text, | |
| "target_lang": target_lang | |
| }, | |
| headers=headers | |
| ) | |
| response.raise_for_status() | |
| return response.json().get("translated_text", "No result") | |
| except Exception as e: | |
| return str(e) | |
| demo = gr.Interface( | |
| fn=translate_text, | |
| inputs=[ | |
| gr.Textbox(label="Text"), | |
| gr.Dropdown(["fr", "de", "ja"], label="Language") | |
| ], | |
| outputs="text", | |
| title="MTF Localization" | |
| ) | |
| demo.launch() |