File size: 804 Bytes
c55bfff
 
 
 
cb7be72
c55bfff
 
 
 
 
 
 
 
cb7be72
 
 
c55bfff
 
 
 
 
 
 
 
 
cb7be72
c55bfff
 
 
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 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()