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