TOUNDE commited on
Commit
162d617
Β·
verified Β·
1 Parent(s): c628af6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -40
app.py CHANGED
@@ -5,18 +5,17 @@ import os
5
 
6
  API_TOKEN = os.environ.get("API_TOKEN")
7
 
 
8
  #changement du logo et du titre de mon application en anglais
9
  st.set_page_config(page_title="TSC", page_icon="books", layout="centered", menu_items=None)
10
 
11
 
12
-
13
  col1, col2, col3 = st.columns(3)
14
  xx = col1
15
  ar = col2.image("keyce.jpg", width=180)
16
  yy = col3
17
 
18
 
19
-
20
  # menu horizontal
21
  selected = option_menu(None, ["Home", "Translate", "Summarization", "Chatbot"],
22
  icons=['house', 'globe', "pencil", "chat"],
@@ -29,7 +28,6 @@ selected = option_menu(None, ["Home", "Translate", "Summarization", "Chatbot"],
29
  })
30
 
31
 
32
-
33
  if selected == "Home":
34
  st.subheader("Welcome to our app !!")
35
  st.info(":blue[We are the present of tomorrow! Please like it after use!]")
@@ -44,44 +42,44 @@ elif selected == 'Translate':
44
  #Boutton pour effectuer la traduction
45
  btn_translate = st.button("🌐 Translate")
46
  if languages == "english - spanish" and text_in:
47
- API_URL = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-es"
48
- headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
49
  if btn_translate:
50
- def query(payload):
51
- response = requests.post(API_URL, headers=headers, json=payload)
52
  return response.json()
53
- output = query({"inputs": text_in})
54
- text_out = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output[0]["translation_text"] +'''</p>''', unsafe_allow_html=True)
55
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
56
  elif languages == "english - french" and text_in:
57
- API_URL = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-fr"
58
- headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
59
  if btn_translate:
60
- def query(payload):
61
- response = requests.post(API_URL, headers=headers, json=payload)
62
  return response.json()
63
- output = query({"inputs": text_in})
64
- text_out = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output[0]["translation_text"] +'''</p>''', unsafe_allow_html=True)
65
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
66
  elif languages == 'english - chinese' and text_in:
67
- API_URL = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-zh"
68
- headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
69
  if btn_translate:
70
- def query(payload):
71
- response = requests.post(API_URL, headers=headers, json=payload)
72
  return response.json()
73
- output = query({"inputs": text_in})
74
- text_out = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output[0]["translation_text"] +'''</p>''', unsafe_allow_html=True)
75
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
76
  elif languages == "english - german" and text_in:
77
- API_URL = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-de"
78
- headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
79
  if btn_translate:
80
- def query(payload):
81
- response = requests.post(API_URL, headers=headers, json=payload)
82
  return response.json()
83
- output = query({"inputs": text_in})
84
- text_out = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output[0]["translation_text"] +'''</p>''', unsafe_allow_html=True)
85
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
86
 
87
  elif selected == 'Summarization':
@@ -90,30 +88,36 @@ elif selected == 'Summarization':
90
  btn_sum = st.button("πŸ“ Summary")
91
  if text_sum:
92
  if btn_sum:
93
- API_URL = "https://api-inference.huggingface.co/models/Falconsai/text_summarization"
94
- headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
95
- def query_sum(payload):
96
- response = requests.post(API_URL, headers=headers, json=payload)
97
  return response.json()
98
  st.markdown('''<h4 style='text-align:left;color:black;'> Answer </h4>''', unsafe_allow_html=True)
99
- output_sum = query_sum({"inputs": text_sum})
100
- 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)
101
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
102
 
103
  elif selected == 'Chatbot':
104
- texte_chat = st.text_input("Enter your question:")
105
  #Boutton pour effectuer le chatbot
106
  btn_chat = st.button("πŸ’¬ Submit")
107
- API_URL = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"
108
- headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
109
 
110
  if texte_chat:
111
  if btn_chat:
112
- def chatbot(payload):
113
- response = requests.post(API_URL, headers=headers, json=payload)
114
  return response.json()
115
- output_chat = chatbot({"inputs": texte_chat})
116
  text_out_chat = st.info(':green['+ output_chat[0] ["generated_text"] +']')
117
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
118
 
119
- st.markdown('''<br/> <h6 style='text-align:center;color:grey;font-size:11px;'> Β© 2024 - TOUNDE - All rights reserved </h6>''', unsafe_allow_html=True)
 
 
 
 
 
 
 
5
 
6
  API_TOKEN = os.environ.get("API_TOKEN")
7
 
8
+
9
  #changement du logo et du titre de mon application en anglais
10
  st.set_page_config(page_title="TSC", page_icon="books", layout="centered", menu_items=None)
11
 
12
 
 
13
  col1, col2, col3 = st.columns(3)
14
  xx = col1
15
  ar = col2.image("keyce.jpg", width=180)
16
  yy = col3
17
 
18
 
 
19
  # menu horizontal
20
  selected = option_menu(None, ["Home", "Translate", "Summarization", "Chatbot"],
21
  icons=['house', 'globe', "pencil", "chat"],
 
28
  })
29
 
30
 
 
31
  if selected == "Home":
32
  st.subheader("Welcome to our app !!")
33
  st.info(":blue[We are the present of tomorrow! Please like it after use!]")
 
42
  #Boutton pour effectuer la traduction
43
  btn_translate = st.button("🌐 Translate")
44
  if languages == "english - spanish" and text_in:
45
+ API_URL_spanish = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-es"
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)
53
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
54
  elif languages == "english - french" and text_in:
55
+ API_URL_french = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-fr"
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)
63
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
64
  elif languages == 'english - chinese' and text_in:
65
+ API_URL_chinese = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-zh"
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)
73
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
74
  elif languages == "english - german" and text_in:
75
+ API_URL_german = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-de"
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)
83
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
84
 
85
  elif selected == 'Summarization':
 
88
  btn_sum = st.button("πŸ“ Summary")
89
  if text_sum:
90
  if btn_sum:
91
+ API_URL_summary = "https://api-inference.huggingface.co/models/Falconsai/text_summarization"
92
+ headers_summary = {"Authorization": API_TOKEN}
93
+ def query_summary(payload):
94
+ response = requests.post(API_URL_summary, headers=headers_summary, json=payload)
95
  return response.json()
96
  st.markdown('''<h4 style='text-align:left;color:black;'> Answer </h4>''', unsafe_allow_html=True)
97
+ output_sum = query_summary({"inputs": text_sum})
98
+ 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)
99
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
100
 
101
  elif selected == 'Chatbot':
102
+ texte_chat = st.text_input("Enter your question")
103
  #Boutton pour effectuer le chatbot
104
  btn_chat = st.button("πŸ’¬ Submit")
105
+ API_URL_chatbot = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"
106
+ headers_chatbot = {"Authorization": API_TOKEN}
107
 
108
  if texte_chat:
109
  if btn_chat:
110
+ def query_chatbot(payload):
111
+ response = requests.post(API_URL_chatbot, headers=headers_chatbot, json=payload)
112
  return response.json()
113
+ output_chat = query_chatbot({"inputs": texte_chat})
114
  text_out_chat = st.info(':green['+ output_chat[0] ["generated_text"] +']')
115
  st.info(":blue[Please feel fit to like it after use! πŸ˜‰πŸ™]")
116
 
117
+ st.markdown('''<br/> <h6 style='text-align:center;color:grey;font-size:11px;'> Β© 2024 - TOUNDE - All rights reserved </h6>''', unsafe_allow_html=True)
118
+
119
+ # for key in range(5):
120
+ # try:
121
+ # text_out = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output[0]["translation_text"] +'''</p>''', unsafe_allow_html=True)
122
+ # except KeyError:
123
+ # print("Couldn't find a match for the key:", key)