File size: 984 Bytes
cf2d2cd
89f5567
31422bd
 
cf2d2cd
0fb793d
89f5567
 
cf2d2cd
89f5567
b48804b
89f5567
 
ef41547
b48804b
 
ef41547
b48804b
 
 
 
d7fc1aa
b48804b
 
cf2d2cd
8b6ba6f
cf2d2cd
 
89f5567
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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()