File size: 884 Bytes
3d78cdc
5c34ad5
3d95bb4
 
3d78cdc
6fd4868
5c34ad5
 
3d78cdc
5c34ad5
 
 
 
 
98df23f
 
 
 
 
1d2a39b
85e2c3f
98df23f
8a9d8b4
3d78cdc
ade53b7
3d78cdc
 
5c34ad5
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
import gradio as gr
import os
import requests
import time

API_URL = "https://api-inference.huggingface.co/models/atlasia/Terjman-Nano"
HF_TOKEN = os.environ['HF_TOKEN']
headers = {"Authorization": "Bearer "+ HF_TOKEN}

def respond(english_text):
    payload  = {
        "inputs": english_text,
    }
    darija_translated_text = requests.post(API_URL, headers=headers, json=payload)
    response = darija_translated_text.json()

    try: 
        output = response[0]['generated_text']
    except KeyError:
        output = f"Model id loading. Estimated time {output['estimated_time']}"
        # output = response
        
    return output 

app = gr.Interface(fn=respond, inputs="text", outputs="text", title="Terjman-Nano πŸ‘¨β€πŸ’» 😊", description="Translate English text to Moroccan Darija using our smallest model (77M) πŸ€—")

if __name__ == "__main__":
    app.launch()