File size: 1,156 Bytes
c2d3401
 
 
 
 
fba231d
ea1fbb8
c2d3401
 
 
 
 
 
 
fba231d
c2d3401
 
 
fba231d
 
c2d3401
 
 
 
 
fba231d
c2d3401
 
 
 
ea1fbb8
fba231d
ea1fbb8
 
fba231d
 
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

import requests
import time


hold_time = time.time()

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

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


def run_model(text):
	global hold_time
	output = query({
	"inputs": text,
	"parameters": {}
})
	if output:
		hold_time = 1
		return output[0]['generated_text']
	else:
		return f'Model is being loaded, please try again in {int((hold_time - time.time()) + 35)} seconds.'
		
	


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