TOUNDE commited on
Commit
1220cb1
·
verified ·
1 Parent(s): 162d617

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -36,7 +36,14 @@ if selected == "Home":
36
  st.write("Hello to everybody! In this Artificial Intelligence app, we offer you a THREE-IN-ONE package. First of all, we've got the (Translate) menu, which lets you do a good job of translating into a few foreign languages, then we've got the (Summary) option, which lets you enter your text in order to summarize it, and finally, as a bonus, we've integrated a chatbot model in the (Chatbot) option, which lets you try out our chatbot, which we're currently perfecting.")
37
 
38
  elif selected == 'Translate':
39
- languages = st.selectbox('Select input and translate languages', ('', 'english - chinese', 'english - french', 'english - german', 'english - spanish'))
 
 
 
 
 
 
 
40
  col3, col4 = st.columns(2)
41
  text_in = col3.text_area("", height=200, placeholder='type or paste the text you wish to translate.')
42
  #Boutton pour effectuer la traduction
@@ -46,7 +53,7 @@ elif selected == 'Translate':
46
  headers_spanish = {"Authorization": API_TOKEN}
47
  if btn_translate:
48
  def query_spanish(payload):
49
- response = requests.post(API_URL_spanish, headers=headers_spanish, json=payload)
50
  return response.json()
51
  output_spanish = query_spanish({"inputs": text_in})
52
  text_out_spanish = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output_spanish[0] ["translation_text"] +'''</p>''', unsafe_allow_html=True)
@@ -56,7 +63,7 @@ elif selected == 'Translate':
56
  headers_french = {"Authorization": API_TOKEN}
57
  if btn_translate:
58
  def query_french(payload):
59
- response = requests.post(API_URL_french, headers=headers_french, json=payload)
60
  return response.json()
61
  output_french = query_french({"inputs": text_in})
62
  text_out_french = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output_french[0] ["translation_text"] +'''</p>''', unsafe_allow_html=True)
@@ -66,7 +73,7 @@ elif selected == 'Translate':
66
  headers_chinese = {"Authorization": API_TOKEN}
67
  if btn_translate:
68
  def query_chinese(payload):
69
- response = requests.post(API_URL_chinese, headers=headers_chinese, json=payload)
70
  return response.json()
71
  output_chinese = query_chinese({"inputs": text_in})
72
  text_out_chinese = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output_chinese[0] ["translation_text"] +'''</p>''', unsafe_allow_html=True)
@@ -76,7 +83,7 @@ elif selected == 'Translate':
76
  headers_german = {"Authorization": API_TOKEN}
77
  if btn_translate:
78
  def query_german(payload):
79
- response = requests.post(API_URL_german, headers=headers_german, json=payload)
80
  return response.json()
81
  output_german = query_german({"inputs": text_in})
82
  text_out_german = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output_german[0] ["translation_text"] +'''</p>''', unsafe_allow_html=True)
 
36
  st.write("Hello to everybody! In this Artificial Intelligence app, we offer you a THREE-IN-ONE package. First of all, we've got the (Translate) menu, which lets you do a good job of translating into a few foreign languages, then we've got the (Summary) option, which lets you enter your text in order to summarize it, and finally, as a bonus, we've integrated a chatbot model in the (Chatbot) option, which lets you try out our chatbot, which we're currently perfecting.")
37
 
38
  elif selected == 'Translate':
39
+ # Choose the translation language
40
+ translation_model = {
41
+ "english - spanish": "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-es",
42
+ "english - french": "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-fr",
43
+ "english - chinese": "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-zh",
44
+ "english - german": "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-de"
45
+ }
46
+ languages = st.selectbox('Select input and translate languages', (list(translation_models.keys()))
47
  col3, col4 = st.columns(2)
48
  text_in = col3.text_area("", height=200, placeholder='type or paste the text you wish to translate.')
49
  #Boutton pour effectuer la traduction
 
53
  headers_spanish = {"Authorization": API_TOKEN}
54
  if btn_translate:
55
  def query_spanish(payload):
56
+ response = requests.post(translation_model, 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)
 
63
  headers_french = {"Authorization": API_TOKEN}
64
  if btn_translate:
65
  def query_french(payload):
66
+ response = requests.post(translation_model, headers=headers_french, json=payload)
67
  return response.json()
68
  output_french = query_french({"inputs": text_in})
69
  text_out_french = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output_french[0] ["translation_text"] +'''</p>''', unsafe_allow_html=True)
 
73
  headers_chinese = {"Authorization": API_TOKEN}
74
  if btn_translate:
75
  def query_chinese(payload):
76
+ response = requests.post(translation_model, headers=headers_chinese, json=payload)
77
  return response.json()
78
  output_chinese = query_chinese({"inputs": text_in})
79
  text_out_chinese = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output_chinese[0] ["translation_text"] +'''</p>''', unsafe_allow_html=True)
 
83
  headers_german = {"Authorization": API_TOKEN}
84
  if btn_translate:
85
  def query_german(payload):
86
+ response = requests.post(translation_model, headers=headers_german, json=payload)
87
  return response.json()
88
  output_german = query_german({"inputs": text_in})
89
  text_out_german = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output_german[0] ["translation_text"] +'''</p>''', unsafe_allow_html=True)