TOUNDE commited on
Commit
ff8d8da
Β·
verified Β·
1 Parent(s): ab9903f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -3
app.py CHANGED
@@ -56,7 +56,14 @@ elif selected == 'Translate':
56
  response = requests.post(API_TRANSLATED, headers=headers_spanish, json=payload)
57
  return response.json()
58
  output_spanish = query_spanish({"inputs": text_in})
59
- text_out_spanish = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output_spanish[0] ["translation_text"] +'''</p>''', unsafe_allow_html=True)
 
 
 
 
 
 
 
60
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
61
  elif languages == "english - french" and text_in:
62
  API_URL_french = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-fr"
@@ -83,7 +90,14 @@ elif selected == 'Translate':
83
  response = requests.post(API_TRANSLATED, headers=headers_chinese, json=payload)
84
  return response.json()
85
  output_chinese = query_chinese({"inputs": text_in})
86
- text_out_chinese = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output_chinese[0] ["translation_text"] +'''</p>''', unsafe_allow_html=True)
 
 
 
 
 
 
 
87
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
88
  elif languages == "english - german" and text_in:
89
  headers_german = {"Authorization": API_TOKEN}
@@ -92,7 +106,14 @@ elif selected == 'Translate':
92
  response = requests.post(API_TRANSLATED, headers=headers_german, json=payload)
93
  return response.json()
94
  output_german = query_german({"inputs": text_in})
95
- text_out_german = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output_german[0] ["translation_text"] +'''</p>''', unsafe_allow_html=True)
 
 
 
 
 
 
 
96
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
97
 
98
  elif selected == 'Summarization':
 
56
  response = requests.post(API_TRANSLATED, headers=headers_spanish, json=payload)
57
  return response.json()
58
  output_spanish = query_spanish({"inputs": text_in})
59
+ if not output_translate[0]["translation_text"]:
60
+ error_message = output_translate[0]["error"]
61
+ st.error(f"Le texte n'a pas pu Γͺtre traduit: {error_message}")
62
+ else:
63
+ translated_text = output_translate[0]["translation_text"]
64
+ col5.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ translated_text +'''</p>''', unsafe_allow_html=True)
65
+
66
+ # text_out_spanish = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output_spanish[0] ["translation_text"] +'''</p>''', unsafe_allow_html=True)
67
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
68
  elif languages == "english - french" and text_in:
69
  API_URL_french = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-fr"
 
90
  response = requests.post(API_TRANSLATED, headers=headers_chinese, json=payload)
91
  return response.json()
92
  output_chinese = query_chinese({"inputs": text_in})
93
+ if not output_translate[0]["translation_text"]:
94
+ error_message = output_translate[0]["error"]
95
+ st.error(f"Le texte n'a pas pu Γͺtre traduit: {error_message}")
96
+ else:
97
+ translated_text = output_translate[0]["translation_text"]
98
+ col5.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ translated_text +'''</p>''', unsafe_allow_html=True)
99
+
100
+ # text_out_chinese = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output_chinese[0] ["translation_text"] +'''</p>''', unsafe_allow_html=True)
101
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
102
  elif languages == "english - german" and text_in:
103
  headers_german = {"Authorization": API_TOKEN}
 
106
  response = requests.post(API_TRANSLATED, headers=headers_german, json=payload)
107
  return response.json()
108
  output_german = query_german({"inputs": text_in})
109
+ if not output_translate[0]["translation_text"]:
110
+ error_message = output_translate[0]["error"]
111
+ st.error(f"Le texte n'a pas pu Γͺtre traduit: {error_message}")
112
+ else:
113
+ translated_text = output_translate[0]["translation_text"]
114
+ col5.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ translated_text +'''</p>''', unsafe_allow_html=True)
115
+
116
+ # text_out_german = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output_german[0] ["translation_text"] +'''</p>''', unsafe_allow_html=True)
117
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
118
 
119
  elif selected == 'Summarization':