Spaces:
No application file
No application file
File size: 6,721 Bytes
00c7225 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
import streamlit as st
import requests
images = {
"ChatBot": "https://recfaces.com/wp-content/uploads/2021/06/voice-recognition-830x571.jpg",
"Text2Speech": "https://img.freepik.com/vecteurs-premium/traducteur-vocal-ligne-isometrique-concept-langues-apprentissage-e-learning-traduction-langues-guide-audio-traducteur-chatbot-intelligence-artificielle_589019-3704.jpg?w=900",
"Translation": "https://as2.ftcdn.net/v2/jpg/00/49/36/65/1000_F_49366575_CRDRRXsM7DrL2AHc06Fa4uoPFTOSh4oj.jpg"
}
# Fonction pour afficher la barre de menu horizontale interactive
def afficher_barre_menu():
# Modifier l'arrière-plan de la barre latérale en fonction du choix
st.markdown(
"""
<style>
[data-testid="stSidebarContent"]{
background-color: #e5e5f7;
opacity: 0.8;
background-image: repeating-radial-gradient( circle at 0 0, transparent 0, #e5e5f7 10px ), repeating-linear-gradient( #f7724555, #f77245 );
font-family: cursive;
justify-content: center;
}
.nav-item {
margin-right: 20px;
color: white;
font-size: 18px;
font-weight: bold;
text-decoration: none;
transition: all 0.3s ease-in-out; /* Animation de transition */
}
.nav-item:hover {
transform: translateY(-3px); /* Animation de légère élévation au survol */
cursor: pointer; /* Curseur pointeur au survol */
}
</style>
""",
unsafe_allow_html=True
)
st.markdown(
"""
<script>
function change_contenu(option) {
const choix = option.toLowerCase();
const elements = document.getElementsByClassName('nav-item');
for (let i = 0; i < elements.length; i++) {
elements[i].classList.remove('selected');
}
document.getElementById(option).classList.add('selected');
const contenu = document.getElementById('contenu');
fetch_data(choix);
}
function fetch_data(choix) {
const descriptions = {
ChatBot: "Description de l'onglet ChatBot",
Text2Speech: "Description de l'onglet Text2Speech",
Translation: "Description de l'onglet Translation"
};
const description = descriptions[choix];
document.getElementById('description').innerText = description;
}
</script>
""",
unsafe_allow_html=True
)
# Fonction pour afficher la barre de description verticale
def afficher_barre_description(description):
st.sidebar.title("Description")
st.sidebar.write(description)
# Fonction principale pour afficher l'application
def main():
afficher_barre_menu()
st.sidebar.header("Principal")
choix = st.sidebar.selectbox("Choose your option ",["ChatBot", "Text2Speech", "Translation"])
if choix == "ChatBot":
afficher_barre_description("This section features a chatbot inspired by Mistral-7B-Instruct-v0.2. Which is able to respond with a high level of expertise NB: for more precision put your text between quote.")
afficher_ChatBot()
elif choix == "Text2Speech":
afficher_barre_description("Enter the text you wish to convert to speech in the text box below, then click the button to listen to the generated speech.")
afficher_Text2Speech()
elif choix == "Translation":
afficher_barre_description("The Hellsinki model is used to translate Korean and Spanish texts into French.")
afficher_Translation()
# Fonctions pour afficher le contenu
def afficher_ChatBot():
st.title("Interactive Chatbot ")
st.write("Welcome all of you.")
# Définir le modèle et le tokenizer
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
headers = {"Authorization":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
# Envoyer le message lorsque l'utilisateur appuie sur Entrée
messages = st.container(height = 300)
if user_input := st.chat_input("Say something"):
output = query({
"inputs": user_input
})
messages.chat_message('user').write(user_input)
with st.spinner('Loading....'):
messages.chat_message("assistant")
messages.write(output[0]['generated_text'])
def afficher_Text2Speech():
st.title("Text2Speech")
API_URL = "https://api-inference.huggingface.co/models/facebook/mms-tts-eng"
headers = {"Authorization": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.content
texte_input = st.text_input("Enter your speech")
if st.button('Conversion'):
with st.spinner("Converting..."):
audio_bytes = query({"inputs": texte_input, })
md = f"""
<audio autoplay="true">
<source src="data:audio/wav;base64" type="audio/mp3">
</audio>
"""
st.markdown(
md,
unsafe_allow_html=True,
)
st.audio(audio_bytes, format="audio/mpeg", loop=True)
def afficher_Translation():
langues = {
"Korean - French": "Helsinki-NLP/opus-mt-ko-fr",
"Espagnol - French": "Helsinki-NLP/opus-mt-es-fr"
}
st.title("Translator")
with st.container(height=500):
langue_source = st.selectbox("Source :", list(langues.keys()))
phrase = st.text_input("Enter the sentence to be translated :")
if st.button("Translate"):
# Récupérer les modèles correspondants aux langues sélectionnées
modele_source = langues[langue_source]
# Appeler l'API pour traduire la phrase
resultat = traduire(phrase, modele_source)
# Afficher le résultat de la traduction
st.markdown("** The translation :**")
st.write(resultat[0]['translation_text'])
# Fonction pour appeler l'API de traduction
def traduire(phrase, modele_source):
API_URL = f"https://api-inference.huggingface.co/models/{modele_source}"
headers = {"Authorization": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}
payload = {"inputs": phrase}
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
# Appel de la fonction principale
if __name__ == "__main__":
main()
|