Spaces:
Running
Running
Florian.Moret
commited on
Commit
·
8a117ed
1
Parent(s):
fb3d9c2
test_app_zephyr
Browse files
app.py
CHANGED
@@ -1,32 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# import streamlit as st
|
2 |
|
3 |
# x = st.slider('Select a value')
|
4 |
# st.write(x, 'squared is', x * x)
|
5 |
|
6 |
-
#test app code de chatgpt
|
7 |
-
import streamlit as st
|
8 |
-
import tensorflow
|
9 |
-
import torch
|
10 |
-
from transformers import pipeline
|
11 |
|
12 |
-
# Chargement du modèle Hugging Face (GPT-2 ou autre modèle de génération de texte)
|
13 |
-
generator = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta", torch_dtype=torch.bfloat16, device_map="auto")
|
14 |
|
15 |
-
# Fonction pour générer une réponse du chatbot
|
16 |
-
def chatbot_response(user_input):
|
17 |
-
|
18 |
-
|
19 |
|
20 |
-
# Interface Streamlit
|
21 |
-
st.title("Expert en nutrition des volailles de chair et de ponte")
|
22 |
|
23 |
-
# Instructions
|
24 |
-
st.markdown("### Posez une question à notre expert !")
|
25 |
|
26 |
-
# Entrée utilisateur
|
27 |
-
user_input = st.text_input("")
|
28 |
|
29 |
-
if user_input:
|
30 |
-
|
31 |
-
|
32 |
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Titre de l'application
|
5 |
+
st.set_page_config(page_title="Chatbot AI", page_icon="🤖")
|
6 |
+
st.title("Chatbot AI avec Hugging Face - Zephyr 7B Beta")
|
7 |
+
|
8 |
+
# Chargement du modèle
|
9 |
+
@st.cache(allow_output_mutation=True)
|
10 |
+
def load_model():
|
11 |
+
return pipeline("text-generation", model="zephyr-7b-beta")
|
12 |
+
|
13 |
+
model = load_model()
|
14 |
+
|
15 |
+
# Interface utilisateur
|
16 |
+
st.sidebar.header("Options")
|
17 |
+
user_input = st.text_input("Vous : ", "")
|
18 |
+
|
19 |
+
if st.button("Envoyer"):
|
20 |
+
if user_input:
|
21 |
+
with st.spinner("Zephyr réfléchit..."):
|
22 |
+
# Génération de la réponse
|
23 |
+
response = model(user_input, max_length=100, num_return_sequences=1)
|
24 |
+
bot_response = response[0]['generated_text']
|
25 |
+
|
26 |
+
st.markdown("**Bot :** " + bot_response)
|
27 |
+
else:
|
28 |
+
st.warning("Veuillez entrer un message!")
|
29 |
+
|
30 |
+
# Styles CSS pour améliorer l'apparence
|
31 |
+
st.markdown("""
|
32 |
+
<style>
|
33 |
+
.st-bx {
|
34 |
+
background-color: #f1f1f1;
|
35 |
+
border-radius: 10px;
|
36 |
+
padding: 10px;
|
37 |
+
margin: 10px 0;
|
38 |
+
}
|
39 |
+
.st-bx h2 {
|
40 |
+
color: #4CAF50;
|
41 |
+
}
|
42 |
+
.st-bx p {
|
43 |
+
color: #555;
|
44 |
+
}
|
45 |
+
</style>
|
46 |
+
""", unsafe_allow_html=True)
|
47 |
+
|
48 |
# import streamlit as st
|
49 |
|
50 |
# x = st.slider('Select a value')
|
51 |
# st.write(x, 'squared is', x * x)
|
52 |
|
53 |
+
# #test app code de chatgpt
|
54 |
+
# import streamlit as st
|
55 |
+
# import tensorflow
|
56 |
+
# import torch
|
57 |
+
# from transformers import pipeline
|
58 |
|
59 |
+
# # Chargement du modèle Hugging Face (GPT-2 ou autre modèle de génération de texte)
|
60 |
+
# generator = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta", torch_dtype=torch.bfloat16, device_map="auto")
|
61 |
|
62 |
+
# # Fonction pour générer une réponse du chatbot
|
63 |
+
# def chatbot_response(user_input):
|
64 |
+
# response = generator(user_input, max_length=100, num_return_sequences=1)
|
65 |
+
# return response[0]['generated_text']
|
66 |
|
67 |
+
# # Interface Streamlit
|
68 |
+
# st.title("Expert en nutrition des volailles de chair et de ponte")
|
69 |
|
70 |
+
# # Instructions
|
71 |
+
# st.markdown("### Posez une question à notre expert !")
|
72 |
|
73 |
+
# # Entrée utilisateur
|
74 |
+
# user_input = st.text_input("")
|
75 |
|
76 |
+
# if user_input:
|
77 |
+
# response = chatbot_response(user_input)
|
78 |
+
# st.write(f"Chatbot : {response}")
|
79 |
|