BounharAbdelaziz commited on
Commit
b1d814b
β€’
1 Parent(s): 8c61996

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -20
app.py CHANGED
@@ -1,27 +1,14 @@
 
1
  import gradio as gr
2
- import os
3
- import requests
4
- import time
5
 
6
-
7
- API_URL = "https://api-inference.huggingface.co/models/atlasia/Terjman-Ultra"
8
- HF_TOKEN = os.environ['HF_TOKEN']
9
- headers = {"Authorization": "Bearer "+ HF_TOKEN}
10
 
11
  def respond(english_text):
12
- payload = {
13
- "inputs": english_text,
14
- }
15
-
16
- while True:
17
- response = requests.post(API_URL, headers=headers, json=payload).json()
18
-
19
- if isinstance(response, list) and 'generated_text' in response[0]:
20
- return response[0]['generated_text']
21
- elif 'estimated_time' in response:
22
- time.sleep(5) # Wait for 5 seconds before retrying
23
- else:
24
- return "An error occurred, please refresh the webpage: " + str(response)
25
 
26
  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) πŸ€—")
27
 
 
1
+ from gradio_client import Client
2
  import gradio as gr
 
 
 
3
 
4
+ client = Client("https://4f122e3ce62b0d809b.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
  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) πŸ€—")
14