|
import streamlit as st |
|
import requests |
|
|
|
API_URL_BART = "https://api-inference.huggingface.co/models/chinhon/bart-large-cnn-summarizer_03" |
|
API_URL_TRANSLATION = "https://api-inference.huggingface.co/models/FacebookAI/xlm-mlm-enfr-1024" |
|
API_URL_DIALOGPT = "https://api-inference.huggingface.co/models/Mohammed-Altaf/Medical-ChatBot" |
|
HEADERS = {"Authorization": f"Bearer {huggingface_token}"} |
|
|
|
def query(api_url, payload): |
|
response = requests.post(api_url, headers=HEADERS, json=payload) |
|
return response.json() |
|
|
|
def main(): |
|
st.title("Application NLP") |
|
|
|
|
|
st.sidebar.image("Keyce.jpg") |
|
st.write("FOSSO TCHATAT SIDOINE") |
|
model_selection = st.sidebar.selectbox("Sélectionnez le modèle", ["BART Summarization", "Translation (fr->en)", "Conversation (BlenderBot-400M)"]) |
|
|
|
if model_selection == "BART Summarization": |
|
|
|
st.subheader("BART Summarization") |
|
st.image("resume.jpg") |
|
|
|
user_input_bart = st.text_area("Entrez le texte :") |
|
|
|
if st.button("Resumer avec BART"): |
|
|
|
payload_bart = {"inputs": user_input_bart} |
|
result_bart = query(API_URL_BART, payload_bart) |
|
|
|
|
|
st.subheader("Résumé:") |
|
st.write(result_bart[0]["generated_text"]) |
|
|
|
elif model_selection == "Translation (fr->en)": |
|
|
|
st.subheader("Translation (fr->en)") |
|
st.image("TRANSLATE.jpg") |
|
|
|
|
|
user_input_translation = st.text_area("Entrez le texte que vous souhaitez traduire:") |
|
|
|
if st.button("🌐 Translate"): |
|
|
|
payload_translation = {"inputs": user_input_translation} |
|
result_translation = query(API_URL_TRANSLATION, payload_translation) |
|
|
|
|
|
|
|
st.subheader("Traduction:") |
|
st.write(result_translation[0]["translation_text"]) |
|
|
|
elif model_selection == "Conversation (BlenderBot-400M)": |
|
st.subheader("Conversation with BlenderBot-400M") |
|
|
|
|
|
user_input_blenderbot = st.text_area("Entrez votre message à BlenderBot-400M:") |
|
|
|
if st.button("Obtenir la réponse de BlenderBot-400M"): |
|
|
|
payload_blenderbot = { |
|
"inputs": { |
|
"past_user_inputs": ["Which movie is the best ?"], |
|
"generated_responses": ["It is Die Hard for sure."], |
|
"text": user_input_blenderbot |
|
} |
|
} |
|
result_blenderbot = query(API_URL_DIALOGPT, payload_blenderbot) |
|
|
|
|
|
st.subheader("Conversation avec BlenderBot-400M:") |
|
|
|
|
|
if "choices" in result_blenderbot and result_blenderbot["choices"]: |
|
|
|
for i, past_message in enumerate(result_blenderbot["choices"][-1]["message"]["past_user_inputs"]): |
|
st.write(f"BlenderBot-400M:") |
|
st.write(f"> {past_message}") |
|
|
|
|
|
st.write("Vous:") |
|
st.write(f"> {user_input_blenderbot}") |
|
|
|
|
|
st.write(f"BlenderBot-400M:") |
|
st.write(f"> {result_blenderbot['choices'][-1]['message']['content']}") |
|
else: |
|
st.warning("La clé 'choices' n'existe pas dans la réponse de l'API ou la liste est vide.") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|