Spaces:
Runtime error
Runtime error
import gradio as gr | |
import os | |
import requests | |
import time | |
API_URL = "https://api-inference.huggingface.co/models/atlasia/Terjman-Large" | |
HF_TOKEN = os.environ['HF_TOKEN'] | |
headers = {"Authorization": "Bearer "+ HF_TOKEN} | |
def respond(english_text): | |
payload = { | |
"inputs": english_text, | |
} | |
while True: | |
response = requests.post(API_URL, headers=headers, json=payload).json() | |
if isinstance(response, list) and 'generated_text' in response[0]: | |
return response[0]['generated_text'] | |
elif 'estimated_time' in response: | |
time.sleep(5) # Wait for 5 seconds before retrying | |
else: | |
return "An error occurred, please refresh the webpage: " + str(response) | |
app = gr.Interface(fn=respond, inputs="text", outputs="text", title="Terjman-Large π¨βπ»π₯°", description="Translate English text to Moroccan Darija using our Large model (240M) π€") | |
if __name__ == "__main__": | |
app.launch() |