Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from streamlit_option_menu import option_menu
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
#changement du logo et du titre de mon application en anglais
|
| 8 |
+
st.set_page_config(page_title="TSC", page_icon="books", layout="centered", menu_items=None)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
col1, col2, col3 = st.columns(3)
|
| 13 |
+
xx = col1
|
| 14 |
+
ar = col2.image("keyce.jpg", width=180)
|
| 15 |
+
yy = col3
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# menu horizontal
|
| 20 |
+
selected = option_menu(None, ["Home", "Translate", "Summarization", "Chatbot"],
|
| 21 |
+
icons=['house', 'globe', "pencil", "chat"],
|
| 22 |
+
menu_icon="cast", default_index=0, orientation="horizontal",
|
| 23 |
+
styles={
|
| 24 |
+
"container": {"padding":"5!important", "background-color":"#000E38", "color":"white"},
|
| 25 |
+
"icon": {"color":"#fff", "font-size":"16px"},
|
| 26 |
+
"nav-link": {"font-size":"16px", "text-align":"left", "margin":"0px", "--hover-color":"#f9d1ac", "color":"white"},
|
| 27 |
+
"nav-link-selected": {"background-color": "#FF9633", "color": "white"},
|
| 28 |
+
})
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
if selected == "Home":
|
| 33 |
+
st.subheader("Welcome to our app !!")
|
| 34 |
+
st.info(":blue[We are the present of tomorrow! Please like it after use!]")
|
| 35 |
+
#Insertion d'une image
|
| 36 |
+
st.image("nlp1.png", width=None)
|
| 37 |
+
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.")
|
| 38 |
+
|
| 39 |
+
elif selected == 'Translate':
|
| 40 |
+
languages = st.selectbox('Select input and translate languages', ('', 'english - chinese', 'english - french', 'english - german', 'english - spanish'))
|
| 41 |
+
col3, col4 = st.columns(2)
|
| 42 |
+
text_in = col3.text_area("", height=200, placeholder='type or paste the text you wish to translate.')
|
| 43 |
+
#Boutton pour effectuer la traduction
|
| 44 |
+
btn_translate = st.button("π Translate")
|
| 45 |
+
if languages == "english - spanish" and text_in:
|
| 46 |
+
API_URL = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-es"
|
| 47 |
+
headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
|
| 48 |
+
if btn_translate:
|
| 49 |
+
def query(payload):
|
| 50 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 51 |
+
return response.json()
|
| 52 |
+
output = query({"inputs": text_in})
|
| 53 |
+
text_out = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output[0]["translation_text"] +'''</p>''', unsafe_allow_html=True)
|
| 54 |
+
st.info(":blue[Please feel fit to like it after use! ππ]")
|
| 55 |
+
elif languages == "english - french" and text_in:
|
| 56 |
+
API_URL = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-fr"
|
| 57 |
+
headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
|
| 58 |
+
if btn_translate:
|
| 59 |
+
def query(payload):
|
| 60 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 61 |
+
return response.json()
|
| 62 |
+
output = query({"inputs": text_in})
|
| 63 |
+
text_out = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output[0]["translation_text"] +'''</p>''', unsafe_allow_html=True)
|
| 64 |
+
st.info(":blue[Please feel fit to like it after use! ππ]")
|
| 65 |
+
elif languages == 'english - chinese' and text_in:
|
| 66 |
+
API_URL = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-zh"
|
| 67 |
+
headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
|
| 68 |
+
if btn_translate:
|
| 69 |
+
def query(payload):
|
| 70 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 71 |
+
return response.json()
|
| 72 |
+
output = query({"inputs": text_in})
|
| 73 |
+
text_out = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output[0]["translation_text"] +'''</p>''', unsafe_allow_html=True)
|
| 74 |
+
st.info(":blue[Please feel fit to like it after use! ππ]")
|
| 75 |
+
elif languages == "english - german" and text_in:
|
| 76 |
+
API_URL = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-de"
|
| 77 |
+
headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
|
| 78 |
+
if btn_translate:
|
| 79 |
+
def query(payload):
|
| 80 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 81 |
+
return response.json()
|
| 82 |
+
output = query({"inputs": text_in})
|
| 83 |
+
text_out = col4.markdown('''<br/> <p style='text-align:left;font-size:16px;'>'''+ output[0]["translation_text"] +'''</p>''', unsafe_allow_html=True)
|
| 84 |
+
st.info(":blue[Please feel fit to like it after use! ππ]")
|
| 85 |
+
|
| 86 |
+
elif selected == 'Summarization':
|
| 87 |
+
text_sum = st.text_area("", height=250, placeholder='Please type or paste the text you wish to summarise here.')
|
| 88 |
+
#Boutton pour effectuer la prΓ©diction
|
| 89 |
+
btn_sum = st.button("π Summary")
|
| 90 |
+
if text_sum:
|
| 91 |
+
if btn_sum:
|
| 92 |
+
API_URL = "https://api-inference.huggingface.co/models/Falconsai/text_summarization"
|
| 93 |
+
headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
|
| 94 |
+
def query_sum(payload):
|
| 95 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 96 |
+
return response.json()
|
| 97 |
+
st.markdown('''<h4 style='text-align:left;color:black;'> Answer </h4>''', unsafe_allow_html=True)
|
| 98 |
+
output_sum = query_sum({"inputs": text_sum})
|
| 99 |
+
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)
|
| 100 |
+
st.info(":blue[Please feel fit to like it after use! ππ]")
|
| 101 |
+
|
| 102 |
+
elif selected == 'Chatbot':
|
| 103 |
+
texte_chat = st.text_input("Entrez un texte")
|
| 104 |
+
#Boutton pour effectuer le chatbot
|
| 105 |
+
btn_chat = st.button("π¬ Submit")
|
| 106 |
+
API_URL = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"
|
| 107 |
+
headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
|
| 108 |
+
|
| 109 |
+
if texte_chat:
|
| 110 |
+
if btn_chat:
|
| 111 |
+
def chatbot(payload):
|
| 112 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 113 |
+
return response.json()
|
| 114 |
+
output_chat = chatbot({"inputs": texte_chat})
|
| 115 |
+
text_out_chat = st.info(':green['+ output_chat[0] ["generated_text"] +']')
|
| 116 |
+
st.info(":blue[Please feel fit to like it after use! ππ]")
|
| 117 |
+
|
| 118 |
+
st.markdown('''<br/> <h6 style='text-align:center;color:grey;font-size:11px;'> Β© 2024 - TOUNDE - All rights reserved </h6>''', unsafe_allow_html=True)
|