import streamlit as st import requests import time from streamlit_option_menu import option_menu import streamlit.components.v1 as components import os #TOKEN_API = os.environ.get("API_TOKEN") TOKEN_API = "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" #changement du logo et du titre de mon application en anglais st.set_page_config(page_title="NLP Outro", page_icon=":brain:", layout="centered", menu_items=None) # Créer trois colonnes de largeur égale col1, col2, col3 = st.columns(3) # Laisser la première et la troisième colonne vides with col1: st.write("") # Afficher le logo dans la deuxième colonne with col2: st.sidebar.image("img/logo2.png", use_column_width=None) with col3: st.write("") with st.sidebar: selected = option_menu( menu_title="Application NLP", # required options=["Accueil", "Chatbot", "Traduction", "Résumer"], # required icons=["house", "chat-dots", "translate","journal-text"], # optional menu_icon="cast", # optional default_index=0 # optional ) if selected == "Accueil": st.title(f"{selected}") # Display home page with app description and logo st.header('Bienvenue sur mon application de nlp qui présente trois principales fonctionalités : le chatbot, la traduction et le résumé de texte.') st.image('img/image4.jpg', ) #st.title('Bienvenue sur l\'application de classification d\'images de radiographies pulmonaires') #st.markdown("
'''+ translated_text +'''
''', unsafe_allow_html=True) #st.success(f"Le texte tratuit: {translated_text}") #st.write("**TRADUCTION** is : {}".format(output[0]["translation_text"])) else: st.warning("Veuillez saisir le texte à traduire.") # Clear button to reset input and result if col7.button("Nettoyer"): translate_input = "" col5.success("Le champ est nettoyé.") st.empty() # Clear previous results if any #END FOR TRANSLATE CODE if selected == "Résumer": #CODE SUMMARIZE st.title(f"{selected}") st.image('img/image3.jpg',) st.markdown("ici vous faites le **Résumer** de vos **texte**.") headers = {"Authorization": TOKEN_API} # Load the API_SUMMARY = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn" # User input for translation summary_input = st.text_area("Entrer le texte à Résumer:", "") if st.button("Résumer"): with st.spinner("Résume..."): # Simulate translation delay for demonstration time.sleep(2) if summary_input: def main1(payload): response = requests.post(API_SUMMARY, headers=headers, json=payload) return response.json() output_summary = main1({"inputs": summary_input}) summary_text = output_summary[0]["summary_text"] st.success(f"Résumé: {summary_text}") else: st.warning("Veuillez saisir le texte à résumer.") # Clear button to reset input and result if st.button("Nettoyer"): summary_input = "" st.success("Le champ est nettoyé.") st.empty() # Clear previous results if any #END CODE SUMMARIZE if selected == "Chatbot": # CODE TRANSLATE st.title(f"{selected}") st.image('img/image3.jpg', caption='Veillez chatter ici en me posant vos questions') #st.markdown("Cette partie vous offre la possibilité de me poser vos **questions**.") headers = {"Authorization": TOKEN_API} # Choose the translation language from Hugging Face translation_models = { "English": "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-fr", "French": "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-fr-en", } selected_translation = st.selectbox("Sélectionner une langue", list(translation_models.keys())) # Load the API_URL = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct" # User input for translation user_input = st.text_area("veillez saisir une question :", "") if (selected_translation=="French"): API_URL_1 = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-fr-en" API_URL_2 = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-fr" # Display loading indicator if st.button("Recherche"): with st.spinner("Rechercher..."): # Simulate translation delay for demonstration time.sleep(2) if user_input: def main(payload): response = requests.post(API_URL_1, headers=headers, json=payload) return response.json() output = main({"inputs": user_input}) text2 = output[0]["translation_text"] if text2: def main1(payload): response = requests.post(API_URL, headers=headers, json=payload) return response.json() output = main1({"inputs": text2}) text3 = output[0]["generated_text"] if text3: def main(payload): response = requests.post(API_URL_2, headers=headers, json=payload) return response.json() output = main({"inputs": text3}) generated_text = output[0]["translation_text"] st.success(f"Réponse: {generated_text}") else: st.warning("Veuillez saisir une question.") else : # Display loading indicator if st.button("Research"): with st.spinner("Researching..."): # Simulate translation delay for demonstration time.sleep(2) if user_input: # Perform translation def main(payload): response = requests.post(API_URL, headers=headers, json=payload) return response.json() output = main({ "inputs": user_input }) generated_text = output[0]["generated_text"] st.success(f"Response: {generated_text}") else: st.warning("Please enter a question.") # Clear button to reset input and result if st.button("Nettoyer"): user_input = "" st.success("Le champ est nettoyé.") st.empty() # Clear previous results if any # END CODE TRANSLATE