File size: 1,106 Bytes
c2d3401
 
 
 
 
ea1fbb8
 
 
c2d3401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea1fbb8
c2d3401
 
 
 
ea1fbb8
 
 
 
 
 
 
 
 
c2d3401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea1fbb8
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
63
64
65
66
67
68
69
70
71

import requests
import time


trial = 0


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):
	global trial
	output = query({
	"inputs": text,
	"parameters": {}
})
	if output:
		trial = 0
		return output[0]['generated_text']
	else:
		trial += 1
		if trial%2==1:
			return 'Model is loading, please try again...'
		else:
			return 'Try one more time, it should work now...'
	


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







import gradio as gr

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

def mode_run(text):
	result = run_model(text)
	return result


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

demo.launch()