imomayiz commited on
Commit
ef41547
Β·
verified Β·
1 Parent(s): 0fb793d

fix error message

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -10,8 +10,15 @@ def respond(english_text):
10
  payload = {
11
  "inputs": english_text,
12
  }
13
- darija_translated_text = requests.post(API_URL, headers=headers, json=payload)
14
- return darija_translated_text.json()[0]["generated_text"]
 
 
 
 
 
 
 
15
 
16
  app = gr.Interface(fn=respond, inputs="text", outputs="text", title="Terjman-Large πŸ‘¨β€πŸ’»πŸ₯°", description="Translate English text to Moroccan Darija using our Large model (240M) πŸ€—")
17
 
 
10
  payload = {
11
  "inputs": english_text,
12
  }
13
+ response = requests.post(API_URL, headers=headers, json=payload)
14
+
15
+ try:
16
+ output = response[0]['generated_text']
17
+
18
+ except KeyError:
19
+ output = f"Model is loading. Estimated time {output['estimated_time']}"
20
+
21
+ return output
22
 
23
  app = gr.Interface(fn=respond, inputs="text", outputs="text", title="Terjman-Large πŸ‘¨β€πŸ’»πŸ₯°", description="Translate English text to Moroccan Darija using our Large model (240M) πŸ€—")
24