fawadrashid commited on
Commit
28490d7
1 Parent(s): 53ba35d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -69,14 +69,18 @@ def predict(message, history):
69
 
70
  # Check if the request was successful
71
  if response.status_code == 200:
72
- # Print the content of the response (the data the server returned)
73
  response_json = response.json()
74
- translation_text = response_json[0]['translation_text']
 
 
 
75
  return translation_text
76
  else:
77
  # Print an error message if something went wrong
 
78
  return "Sorry I could not answer your question as something went wrong"
79
- #print(f"Request failed with status code {response.status_code}: {response.text}")
80
  return "Sorry I could not answer your question as something went wrong"
81
 
82
  gr.ChatInterface(predict).launch()
 
69
 
70
  # Check if the request was successful
71
  if response.status_code == 200:
72
+ # Print the content of the response (the data the server returned)
73
  response_json = response.json()
74
+ translation_item = response_json[0] if response_json else {}
75
+ print(response_json)
76
+ # Now use .get() to safely get the 'translation_text'
77
+ translation_text = translation_item.get('translation_text', 'No translation found.')
78
  return translation_text
79
  else:
80
  # Print an error message if something went wrong
81
+ print(f"Request failed with status code {response.status_code}: {response.text}")
82
  return "Sorry I could not answer your question as something went wrong"
83
+
84
  return "Sorry I could not answer your question as something went wrong"
85
 
86
  gr.ChatInterface(predict).launch()