File size: 1,007 Bytes
c2d3401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

import requests
import time


API_URL = "https://cm7kxsqi3sekfih7.us-east-1.aws.endpoints.huggingface.cloud"
headers = {
	"Accept" : "application/json",
	"Content-Type": "application/json" 
}

def query(payload):
	response = requests.post(API_URL, headers=headers, json=payload)
	if response.status_code != 200:
		print('Sleeping due to API error')
		time.sleep(18)
		return None
	return response.json()


def run_model(text):
	output = query({
	"inputs": text,
	"parameters": {}
})
	return output[0]['generated_text'] if output is not None else None
	


run_model('السلام عيكم')







import gradio as gr

examples = [
    ["ما ابغا أروح الإمتحان"],
    ["أييد أن انام ف لبيتنا"],
	["Hello how are you today"]
]

def mode_run(text):
	result = run_model(text)
	if result:
		return result
	else:
		return "Model is running please try again..."


demo = gr.Interface(fn=mode_run,
					inputs="text",
					outputs="text",
					examples=examples)

demo.launch()