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