BounharAbdelaziz commited on
Commit
b6ec47e
β€’
1 Parent(s): 70d496b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -1,15 +1,24 @@
1
  from gradio_client import Client
2
  import gradio as gr
3
 
4
- client = Client("https://83db3eb39c953bd85d.gradio.live/")
 
 
5
 
6
  def respond(english_text):
7
- darija_translated_text = client.predict(
8
- text=english_text,
9
- api_name="/predict"
10
- )
11
- return darija_translated_text
12
-
 
 
 
 
 
 
 
13
 
14
  app = gr.Interface(fn=respond, inputs="text", outputs="text", title="Terjman-Ultra πŸ‘¨β€πŸ’»πŸ€©", description="Translate English text to Moroccan Darija using our second biggest model (1.3B) πŸ€—")
15
 
 
1
  from gradio_client import Client
2
  import gradio as gr
3
 
4
+ API_URL = "https://api-inference.huggingface.co/models/atlasia/Terjman-Ultra"
5
+ HF_TOKEN = os.environ['HF_TOKEN']
6
+ headers = {"Authorization": "Bearer "+ HF_TOKEN}
7
 
8
  def respond(english_text):
9
+ payload = {
10
+ "inputs": english_text,
11
+ }
12
+
13
+ while True:
14
+ response = requests.post(API_URL, headers=headers, json=payload).json()
15
+
16
+ if isinstance(response, list) and 'generated_text' in response[0]:
17
+ return response[0]['generated_text']
18
+ elif 'estimated_time' in response:
19
+ time.sleep(5) # Wait for 5 seconds before retrying
20
+ else:
21
+ return "An error occurred, please refresh the webpage: " + str(response)
22
 
23
  app = gr.Interface(fn=respond, inputs="text", outputs="text", title="Terjman-Ultra πŸ‘¨β€πŸ’»πŸ€©", description="Translate English text to Moroccan Darija using our second biggest model (1.3B) πŸ€—")
24