Spaces:
Runtime error
Runtime error
BounharAbdelaziz
commited on
Commit
β’
b48804b
1
Parent(s):
30aa664
Update app.py
Browse files
app.py
CHANGED
@@ -7,21 +7,20 @@ HF_TOKEN = os.environ['HF_TOKEN']
|
|
7 |
headers = {"Authorization": "Bearer "+ HF_TOKEN}
|
8 |
|
9 |
def respond(english_text):
|
10 |
-
payload
|
11 |
"inputs": english_text,
|
12 |
}
|
13 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
14 |
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
21 |
else:
|
22 |
-
|
23 |
-
|
24 |
-
return output
|
25 |
|
26 |
app = gr.Interface(fn=respond, inputs="text", outputs="text", title="Terjman-Large π¨βπ»π₯°", description="Translate English text to Moroccan Darija using our Large model (240M) π€")
|
27 |
|
|
|
7 |
headers = {"Authorization": "Bearer "+ HF_TOKEN}
|
8 |
|
9 |
def respond(english_text):
|
10 |
+
payload = {
|
11 |
"inputs": english_text,
|
12 |
}
|
|
|
13 |
|
14 |
+
while True:
|
15 |
+
response = requests.post(API_URL, headers=headers, json=payload).json()
|
16 |
|
17 |
+
if isinstance(response, list) and 'generated_text' in response[0]:
|
18 |
+
return response[0]['generated_text']
|
19 |
+
elif 'estimated_time' in response:
|
20 |
+
time.sleep(5) # Wait for 5 seconds before retrying
|
21 |
else:
|
22 |
+
return "An error occurred, please refresh the webpage: " + str(response)
|
23 |
+
|
|
|
24 |
|
25 |
app = gr.Interface(fn=respond, inputs="text", outputs="text", title="Terjman-Large π¨βπ»π₯°", description="Translate English text to Moroccan Darija using our Large model (240M) π€")
|
26 |
|