Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import json | |
| import requests | |
| API_URL = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-ga" | |
| headers = {"Authorization": "Bearer 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"} | |
| def translate(English): | |
| payload = { | |
| "inputs": English, | |
| } | |
| response = requests.post(API_URL, headers=headers, json=payload) | |
| httpresponse = response.json() | |
| # print(httpresponse) | |
| # return httpresponse[0]["generated_text"] | |
| return httpresponse[0]["translation_text"] | |
| iface = gr.Interface( | |
| fn=translate, | |
| inputs=gr.inputs.Textbox(lines=2, placeholder="Shall I compare thee to a Summer's day..."), | |
| outputs="text", | |
| theme="dark-peach", | |
| layout='aligned' | |
| ) | |
| gr.outputs.Textbox(type="str", label="Irish") | |
| if __name__ == "__main__": | |
| app, local_url, share_url = iface.launch() |