Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,15 +52,15 @@ elif selected == 'Translate':
|
|
| 52 |
if btn_translate:
|
| 53 |
headers_spanish = {"Authorization": API_TOKEN}
|
| 54 |
if languages == "english - spanish" and text_in:
|
| 55 |
-
def
|
| 56 |
response = requests.post(API_TRANSLATED, headers=headers_spanish, json=payload)
|
| 57 |
return response.json()
|
| 58 |
-
|
| 59 |
-
if not
|
| 60 |
-
error_message =
|
| 61 |
st.error(f"Le texte n'a pas pu être traduit: {error_message}")
|
| 62 |
else:
|
| 63 |
-
translated_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)
|
|
@@ -69,13 +69,13 @@ elif selected == 'Translate':
|
|
| 69 |
API_URL_french = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-fr"
|
| 70 |
headers_french = {"Authorization": API_TOKEN}
|
| 71 |
if btn_translate:
|
| 72 |
-
def
|
| 73 |
response = requests.post(API_TRANSLATED, headers=headers_french, json=payload)
|
| 74 |
return response.json()
|
| 75 |
-
|
| 76 |
|
| 77 |
-
if not
|
| 78 |
-
error_message =
|
| 79 |
st.error(f"Le texte n'a pas pu être traduit: {error_message}")
|
| 80 |
else:
|
| 81 |
translated_text = output_translate[0]["translation_text"]
|
|
@@ -86,15 +86,15 @@ elif selected == 'Translate':
|
|
| 86 |
elif languages == 'english - chinese' and text_in:
|
| 87 |
headers_chinese = {"Authorization": API_TOKEN}
|
| 88 |
if btn_translate:
|
| 89 |
-
def
|
| 90 |
response = requests.post(API_TRANSLATED, headers=headers_chinese, json=payload)
|
| 91 |
return response.json()
|
| 92 |
-
|
| 93 |
-
if not
|
| 94 |
-
error_message =
|
| 95 |
st.error(f"Le texte n'a pas pu être traduit: {error_message}")
|
| 96 |
else:
|
| 97 |
-
translated_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)
|
|
@@ -102,15 +102,15 @@ elif selected == 'Translate':
|
|
| 102 |
elif languages == "english - german" and text_in:
|
| 103 |
headers_german = {"Authorization": API_TOKEN}
|
| 104 |
if btn_translate:
|
| 105 |
-
def
|
| 106 |
response = requests.post(API_TRANSLATED, headers=headers_german, json=payload)
|
| 107 |
return response.json()
|
| 108 |
-
|
| 109 |
-
if not
|
| 110 |
-
error_message =
|
| 111 |
st.error(f"Le texte n'a pas pu être traduit: {error_message}")
|
| 112 |
else:
|
| 113 |
-
translated_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)
|
|
@@ -124,12 +124,12 @@ elif selected == 'Summarization':
|
|
| 124 |
if text_sum:
|
| 125 |
API_URL_summary = "https://api-inference.huggingface.co/models/Falconsai/text_summarization"
|
| 126 |
headers_summary = {"Authorization": API_TOKEN}
|
| 127 |
-
def
|
| 128 |
response = requests.post(API_URL_summary, headers=headers_summary, json=payload)
|
| 129 |
return response.json()
|
| 130 |
st.markdown('''<h4 style='text-align:left;color:black;'> Answer </h4>''', unsafe_allow_html=True)
|
| 131 |
-
|
| 132 |
-
summary_text =
|
| 133 |
st.success(f"Response: {summary_text}")
|
| 134 |
# text_out_sum = st.markdown('''<p style='text-align:left;font-size:16px;color:orange;font-weight:bold'>'''+ output_sum[0]["summary_text"] +'''</p>''', unsafe_allow_html=True)
|
| 135 |
st.info(":blue[Please feel fit to like it after use! 😉🙏]")
|
|
@@ -142,11 +142,11 @@ elif selected == 'Chatbot':
|
|
| 142 |
headers_chatbot = {"Authorization": API_TOKEN}
|
| 143 |
if btn_chat:
|
| 144 |
if text_chat:
|
| 145 |
-
def
|
| 146 |
response = requests.post(API_URL_chatbot, headers=headers_chatbot, json=payload)
|
| 147 |
return response.json()
|
| 148 |
-
|
| 149 |
-
generated_text =
|
| 150 |
st.success(f"Response: {generated_text}")
|
| 151 |
# text_out_chat = st.info(':green['+ output_chat[0]["generated_text"] +']')
|
| 152 |
st.info(":blue[Please feel fit to like it after use! 😉🙏]")
|
|
|
|
| 52 |
if btn_translate:
|
| 53 |
headers_spanish = {"Authorization": API_TOKEN}
|
| 54 |
if languages == "english - spanish" and text_in:
|
| 55 |
+
def query(payload):
|
| 56 |
response = requests.post(API_TRANSLATED, headers=headers_spanish, json=payload)
|
| 57 |
return response.json()
|
| 58 |
+
output = query_spanish({"inputs": text_in})
|
| 59 |
+
if not output[0]["translation_text"]:
|
| 60 |
+
error_message = output[0]["error"]
|
| 61 |
st.error(f"Le texte n'a pas pu être traduit: {error_message}")
|
| 62 |
else:
|
| 63 |
+
translated_text = output[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)
|
|
|
|
| 69 |
API_URL_french = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-fr"
|
| 70 |
headers_french = {"Authorization": API_TOKEN}
|
| 71 |
if btn_translate:
|
| 72 |
+
def query(payload):
|
| 73 |
response = requests.post(API_TRANSLATED, headers=headers_french, json=payload)
|
| 74 |
return response.json()
|
| 75 |
+
output = query({"inputs": text_in})
|
| 76 |
|
| 77 |
+
if not output[0]["translation_text"]:
|
| 78 |
+
error_message = output[0]["error"]
|
| 79 |
st.error(f"Le texte n'a pas pu être traduit: {error_message}")
|
| 80 |
else:
|
| 81 |
translated_text = output_translate[0]["translation_text"]
|
|
|
|
| 86 |
elif languages == 'english - chinese' and text_in:
|
| 87 |
headers_chinese = {"Authorization": API_TOKEN}
|
| 88 |
if btn_translate:
|
| 89 |
+
def query(payload):
|
| 90 |
response = requests.post(API_TRANSLATED, headers=headers_chinese, json=payload)
|
| 91 |
return response.json()
|
| 92 |
+
output = query({"inputs": text_in})
|
| 93 |
+
if not output[0]["translation_text"]:
|
| 94 |
+
error_message = output[0]["error"]
|
| 95 |
st.error(f"Le texte n'a pas pu être traduit: {error_message}")
|
| 96 |
else:
|
| 97 |
+
translated_text = output[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)
|
|
|
|
| 102 |
elif languages == "english - german" and text_in:
|
| 103 |
headers_german = {"Authorization": API_TOKEN}
|
| 104 |
if btn_translate:
|
| 105 |
+
def query(payload):
|
| 106 |
response = requests.post(API_TRANSLATED, headers=headers_german, json=payload)
|
| 107 |
return response.json()
|
| 108 |
+
output = query({"inputs": text_in})
|
| 109 |
+
if not output[0]["translation_text"]:
|
| 110 |
+
error_message = output[0]["error"]
|
| 111 |
st.error(f"Le texte n'a pas pu être traduit: {error_message}")
|
| 112 |
else:
|
| 113 |
+
translated_text = output[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)
|
|
|
|
| 124 |
if text_sum:
|
| 125 |
API_URL_summary = "https://api-inference.huggingface.co/models/Falconsai/text_summarization"
|
| 126 |
headers_summary = {"Authorization": API_TOKEN}
|
| 127 |
+
def query(payload):
|
| 128 |
response = requests.post(API_URL_summary, headers=headers_summary, json=payload)
|
| 129 |
return response.json()
|
| 130 |
st.markdown('''<h4 style='text-align:left;color:black;'> Answer </h4>''', unsafe_allow_html=True)
|
| 131 |
+
output = query({"inputs": text_sum,})
|
| 132 |
+
summary_text = output[0]["summary_text"]
|
| 133 |
st.success(f"Response: {summary_text}")
|
| 134 |
# text_out_sum = st.markdown('''<p style='text-align:left;font-size:16px;color:orange;font-weight:bold'>'''+ output_sum[0]["summary_text"] +'''</p>''', unsafe_allow_html=True)
|
| 135 |
st.info(":blue[Please feel fit to like it after use! 😉🙏]")
|
|
|
|
| 142 |
headers_chatbot = {"Authorization": API_TOKEN}
|
| 143 |
if btn_chat:
|
| 144 |
if text_chat:
|
| 145 |
+
def query(payload):
|
| 146 |
response = requests.post(API_URL_chatbot, headers=headers_chatbot, json=payload)
|
| 147 |
return response.json()
|
| 148 |
+
output = query({"inputs": text_chat,})
|
| 149 |
+
generated_text = output[0]["generated_text"]
|
| 150 |
st.success(f"Response: {generated_text}")
|
| 151 |
# text_out_chat = st.info(':green['+ output_chat[0]["generated_text"] +']')
|
| 152 |
st.info(":blue[Please feel fit to like it after use! 😉🙏]")
|