Spaces:
Runtime error
Runtime error
BounharAbdelaziz
commited on
Commit
β’
b6ec47e
1
Parent(s):
70d496b
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,24 @@
|
|
1 |
from gradio_client import Client
|
2 |
import gradio as gr
|
3 |
|
4 |
-
|
|
|
|
|
5 |
|
6 |
def respond(english_text):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
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 |
|