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()