Spaces:
Runtime error
Runtime error
jwphantom
commited on
Commit
•
a87363f
1
Parent(s):
ad91ef3
finish nlp
Browse files- app.py +10 -3
- modules/chatbot.py +13 -6
- modules/image_classification.py +15 -10
- modules/image_to_text.py +15 -12
- modules/text_to_speech.py +9 -4
- utils/helpers.py +13 -0
- utils/styles.py +49 -0
app.py
CHANGED
@@ -16,9 +16,10 @@ with st.sidebar:
|
|
16 |
"Onyx AI",
|
17 |
["Acceuil", "Documentation"],
|
18 |
icons=["play-btn", "info-circle"],
|
19 |
-
menu_icon="
|
20 |
default_index=0,
|
21 |
styles={
|
|
|
22 |
"icon": {"color": "#374151", "font-size": "17px"},
|
23 |
"nav-link": {
|
24 |
"font-size": "17px",
|
@@ -53,14 +54,20 @@ if menu == "Acceuil":
|
|
53 |
default_index=0,
|
54 |
orientation="horizontal",
|
55 |
styles={
|
56 |
-
"container": {
|
|
|
|
|
|
|
|
|
57 |
"icon": {"color": "#374151", "font-size": "17px"},
|
58 |
"nav-link": {
|
59 |
"font-size": "17px",
|
60 |
"text-align": "left",
|
61 |
"--hover-color": "#eee",
|
62 |
},
|
63 |
-
"nav-link-selected": {
|
|
|
|
|
64 |
},
|
65 |
)
|
66 |
|
|
|
16 |
"Onyx AI",
|
17 |
["Acceuil", "Documentation"],
|
18 |
icons=["play-btn", "info-circle"],
|
19 |
+
menu_icon="rocket",
|
20 |
default_index=0,
|
21 |
styles={
|
22 |
+
"container": {"background-color": "transparent"},
|
23 |
"icon": {"color": "#374151", "font-size": "17px"},
|
24 |
"nav-link": {
|
25 |
"font-size": "17px",
|
|
|
54 |
default_index=0,
|
55 |
orientation="horizontal",
|
56 |
styles={
|
57 |
+
"container": {
|
58 |
+
"background-color": "#fafafa",
|
59 |
+
"border-radius": "8px",
|
60 |
+
"background": "#fbfafa",
|
61 |
+
},
|
62 |
"icon": {"color": "#374151", "font-size": "17px"},
|
63 |
"nav-link": {
|
64 |
"font-size": "17px",
|
65 |
"text-align": "left",
|
66 |
"--hover-color": "#eee",
|
67 |
},
|
68 |
+
"nav-link-selected": {
|
69 |
+
"background-color": "#519ba7",
|
70 |
+
},
|
71 |
},
|
72 |
)
|
73 |
|
modules/chatbot.py
CHANGED
@@ -16,7 +16,7 @@ def show():
|
|
16 |
st.markdown(
|
17 |
"""
|
18 |
<div class='content'>
|
19 |
-
<
|
20 |
</div>
|
21 |
<br/>
|
22 |
<p>Bienvenue dans la section Chatbot intelligent.</p>
|
@@ -60,8 +60,15 @@ def show():
|
|
60 |
# Affiche la requête de l'utilisateur.
|
61 |
st.chat_message(USER).write(prompt)
|
62 |
# Génère une réponse en utilisant le modèle de chatbot.
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
st.markdown(
|
17 |
"""
|
18 |
<div class='content'>
|
19 |
+
<h2>Chatbot intelligent</h2>
|
20 |
</div>
|
21 |
<br/>
|
22 |
<p>Bienvenue dans la section Chatbot intelligent.</p>
|
|
|
60 |
# Affiche la requête de l'utilisateur.
|
61 |
st.chat_message(USER).write(prompt)
|
62 |
# Génère une réponse en utilisant le modèle de chatbot.
|
63 |
+
|
64 |
+
try:
|
65 |
+
generate = model.generate_content(prompt)
|
66 |
+
response: str = generate.text
|
67 |
+
# Ajoute la réponse du chatbot à la liste des messages et l'affiche.
|
68 |
+
st.session_state[MESSAGES].append(
|
69 |
+
Message(actor=ASSISTANT, payload=response)
|
70 |
+
)
|
71 |
+
st.chat_message(ASSISTANT).write(response)
|
72 |
+
|
73 |
+
except Exception as e:
|
74 |
+
st.chat_message(ASSISTANT).text("Erreur bien vouloir recommancer")
|
modules/image_classification.py
CHANGED
@@ -1,9 +1,11 @@
|
|
|
|
1 |
from attr import dataclass
|
2 |
from deep_translator import GoogleTranslator
|
3 |
import pycountry
|
4 |
import requests
|
5 |
import streamlit as st
|
6 |
from langdetect import detect
|
|
|
7 |
|
8 |
from .config import HUGGINGFACE_API_KEY
|
9 |
|
@@ -15,7 +17,7 @@ def show():
|
|
15 |
st.markdown(
|
16 |
"""
|
17 |
<div class='content'>
|
18 |
-
<
|
19 |
</div>
|
20 |
<br/>
|
21 |
<p>Découvrez la classification d'images avec zerp shot.</p>
|
@@ -47,7 +49,9 @@ def show():
|
|
47 |
st.session_state["default_label"] = "voiture,ananas,pastèque,tomate,bouteille"
|
48 |
|
49 |
# Interface utilisateur pour l'entrée de l'image et du libellé
|
50 |
-
uploaded_image = st.file_uploader(
|
|
|
|
|
51 |
|
52 |
st.markdown(
|
53 |
"Veuillez entrer les labels séparés par des virgules (exemple : voiture,ananas,pastèque,tomate,bouteille):"
|
@@ -71,21 +75,22 @@ def show():
|
|
71 |
source="auto", target="en"
|
72 |
).translate(label)
|
73 |
|
74 |
-
labels = convert_label_to_english.split(
|
75 |
-
","
|
76 |
-
) # Splitting the input label string into a list
|
77 |
|
78 |
print(labels)
|
79 |
|
80 |
parameters = {"candidate_labels": labels}
|
81 |
|
82 |
-
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
87 |
|
88 |
-
|
|
|
89 |
|
90 |
else:
|
91 |
st.write("Please upload an image and enter a label.")
|
|
|
1 |
+
import base64
|
2 |
from attr import dataclass
|
3 |
from deep_translator import GoogleTranslator
|
4 |
import pycountry
|
5 |
import requests
|
6 |
import streamlit as st
|
7 |
from langdetect import detect
|
8 |
+
from PIL import Image
|
9 |
|
10 |
from .config import HUGGINGFACE_API_KEY
|
11 |
|
|
|
17 |
st.markdown(
|
18 |
"""
|
19 |
<div class='content'>
|
20 |
+
<h2>Zero shot image classification</h2>
|
21 |
</div>
|
22 |
<br/>
|
23 |
<p>Découvrez la classification d'images avec zerp shot.</p>
|
|
|
49 |
st.session_state["default_label"] = "voiture,ananas,pastèque,tomate,bouteille"
|
50 |
|
51 |
# Interface utilisateur pour l'entrée de l'image et du libellé
|
52 |
+
uploaded_image = st.file_uploader(
|
53 |
+
"Upload an image", type=["jpg", "png", "jpeg"], accept_multiple_files=False
|
54 |
+
)
|
55 |
|
56 |
st.markdown(
|
57 |
"Veuillez entrer les labels séparés par des virgules (exemple : voiture,ananas,pastèque,tomate,bouteille):"
|
|
|
75 |
source="auto", target="en"
|
76 |
).translate(label)
|
77 |
|
78 |
+
labels = convert_label_to_english.split(",")
|
|
|
|
|
79 |
|
80 |
print(labels)
|
81 |
|
82 |
parameters = {"candidate_labels": labels}
|
83 |
|
84 |
+
try:
|
85 |
|
86 |
+
response = query(image_bytes, parameters)
|
87 |
+
translated = GoogleTranslator(source="auto", target="fr").translate(
|
88 |
+
f"The highest score is {response[0]['score']:.3f} for the label {response[0]['label']}"
|
89 |
+
)
|
90 |
+
st.chat_message(ASSISTANT).text(translated)
|
91 |
|
92 |
+
except Exception as e:
|
93 |
+
st.chat_message(ASSISTANT).text("Erreur bien vouloir recommancer")
|
94 |
|
95 |
else:
|
96 |
st.write("Please upload an image and enter a label.")
|
modules/image_to_text.py
CHANGED
@@ -15,7 +15,7 @@ def show():
|
|
15 |
st.markdown(
|
16 |
"""
|
17 |
<div class='content'>
|
18 |
-
<
|
19 |
</div>
|
20 |
<br/>
|
21 |
<p>Convertissez des images en texte grâce à notre outil.</p>
|
@@ -36,7 +36,7 @@ def show():
|
|
36 |
|
37 |
# Interface utilisateur pour l'entrée de l'image et du libellé
|
38 |
uploaded_image_ImgTText = st.file_uploader(
|
39 |
-
"Upload an image", type=["jpg", "png", "jpeg"]
|
40 |
)
|
41 |
|
42 |
# Bouton pour envoyer l'image et le libellé
|
@@ -49,20 +49,23 @@ def show():
|
|
49 |
|
50 |
st.chat_message(ASSISTANT).text("Génération en cours...")
|
51 |
|
52 |
-
|
53 |
-
["Write a short description of the image", image],
|
54 |
-
stream=True,
|
55 |
-
)
|
56 |
|
57 |
-
|
|
|
|
|
|
|
58 |
|
59 |
-
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
|
|
|
|
|
|
|
66 |
|
67 |
else:
|
68 |
st.write("Please upload an image and enter a label.")
|
|
|
15 |
st.markdown(
|
16 |
"""
|
17 |
<div class='content'>
|
18 |
+
<h2>Image to text</h2>
|
19 |
</div>
|
20 |
<br/>
|
21 |
<p>Convertissez des images en texte grâce à notre outil.</p>
|
|
|
36 |
|
37 |
# Interface utilisateur pour l'entrée de l'image et du libellé
|
38 |
uploaded_image_ImgTText = st.file_uploader(
|
39 |
+
"Upload an image", type=["jpg", "png", "jpeg"], accept_multiple_files=False
|
40 |
)
|
41 |
|
42 |
# Bouton pour envoyer l'image et le libellé
|
|
|
49 |
|
50 |
st.chat_message(ASSISTANT).text("Génération en cours...")
|
51 |
|
52 |
+
try:
|
|
|
|
|
|
|
53 |
|
54 |
+
response = model_pro_vision.generate_content(
|
55 |
+
["Write a short description of the image", image],
|
56 |
+
stream=True,
|
57 |
+
)
|
58 |
|
59 |
+
response.resolve()
|
60 |
|
61 |
+
translated = GoogleTranslator(source="auto", target="fr").translate(
|
62 |
+
response.text
|
63 |
+
)
|
64 |
|
65 |
+
st.chat_message(ASSISTANT).text(translated)
|
66 |
+
|
67 |
+
except Exception as e:
|
68 |
+
st.chat_message(ASSISTANT).text("Erreur bien vouloir recommancer")
|
69 |
|
70 |
else:
|
71 |
st.write("Please upload an image and enter a label.")
|
modules/text_to_speech.py
CHANGED
@@ -16,7 +16,7 @@ def show():
|
|
16 |
st.markdown(
|
17 |
"""
|
18 |
<div class='content'>
|
19 |
-
<
|
20 |
</div>
|
21 |
<br/>
|
22 |
<p>Bienvenue dans la section Text to speech en espagnol.</p>
|
@@ -68,8 +68,13 @@ def show():
|
|
68 |
f"Langue détecté {lang_name} \n \n {translated} \n \n Génération de l'audio ..."
|
69 |
)
|
70 |
|
71 |
-
|
72 |
|
73 |
-
|
74 |
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
16 |
st.markdown(
|
17 |
"""
|
18 |
<div class='content'>
|
19 |
+
<h2>Text to speech</h2>
|
20 |
</div>
|
21 |
<br/>
|
22 |
<p>Bienvenue dans la section Text to speech en espagnol.</p>
|
|
|
68 |
f"Langue détecté {lang_name} \n \n {translated} \n \n Génération de l'audio ..."
|
69 |
)
|
70 |
|
71 |
+
try:
|
72 |
|
73 |
+
parameters = {"inputs": translated}
|
74 |
|
75 |
+
audio = query(parameters)
|
76 |
+
|
77 |
+
st.chat_message(ASSISTANT).audio(data=audio)
|
78 |
+
|
79 |
+
except Exception as e:
|
80 |
+
st.chat_message(ASSISTANT).text("Erreur bien vouloir recommancer")
|
utils/helpers.py
CHANGED
@@ -76,7 +76,20 @@ def show():
|
|
76 |
```
|
77 |
|
78 |
### Conversion d'Images en Texte
|
|
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
|
82 |
""",
|
|
|
76 |
```
|
77 |
|
78 |
### Conversion d'Images en Texte
|
79 |
+
Utilise le modèle gemini-pro-vision de Google pour produire une description détaillé d'une image
|
80 |
|
81 |
+
```python
|
82 |
+
|
83 |
+
model = genai.GenerativeModel("gemini-pro-vision")
|
84 |
+
|
85 |
+
response = model.generate_content(image)
|
86 |
+
|
87 |
+
print(response.text)
|
88 |
+
|
89 |
+
```
|
90 |
+
|
91 |
+
<br/>
|
92 |
+
<br/>
|
93 |
|
94 |
|
95 |
""",
|
utils/styles.py
CHANGED
@@ -11,9 +11,58 @@ def apply_styles():
|
|
11 |
background: #fbfafa;
|
12 |
padding : 0 10px 0 20px
|
13 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
.stChatMessage .markdown-text-container {
|
15 |
word-wrap: break-word;
|
16 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
</style>
|
18 |
""",
|
19 |
unsafe_allow_html=True,
|
|
|
11 |
background: #fbfafa;
|
12 |
padding : 0 10px 0 20px
|
13 |
}
|
14 |
+
|
15 |
+
.content h2{
|
16 |
+
text-transform : uppercase;
|
17 |
+
font-size : 25px;
|
18 |
+
font-weight : 700;
|
19 |
+
color: #519ba7
|
20 |
+
}
|
21 |
.stChatMessage .markdown-text-container {
|
22 |
word-wrap: break-word;
|
23 |
}
|
24 |
+
|
25 |
+
[data-testid="stSidebarUserContent"] {
|
26 |
+
background-color: #f0f2f6; /* Couleur de fond de la barre latérale */
|
27 |
+
color: #333; /* Couleur du texte dans la barre latérale */
|
28 |
+
/* Autres styles CSS ici */
|
29 |
+
}
|
30 |
+
|
31 |
+
.menu .container-xxl[data-v-5af006b8] {
|
32 |
+
background-color: transparent;
|
33 |
+
border-radius: 30rem;
|
34 |
+
}
|
35 |
+
|
36 |
+
#MainMenu, header, footer{
|
37 |
+
visibility: hidden;
|
38 |
+
}
|
39 |
+
|
40 |
+
|
41 |
+
section[data-testid="stSidebar"] div:first-child {
|
42 |
+
top: 0;
|
43 |
+
height: 100vh;
|
44 |
+
}
|
45 |
+
|
46 |
+
.block-container {
|
47 |
+
padding-top: 2rem;
|
48 |
+
padding-bottom: 0rem;
|
49 |
+
padding-left: 5rem;
|
50 |
+
padding-right: 5rem;
|
51 |
+
}
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
/* Personnaliser l'arrière-plan de la zone de saisie de chat */
|
56 |
+
.stChatInput textarea {
|
57 |
+
background-color: #212121; /* Couleur de fond légère */
|
58 |
+
}
|
59 |
+
|
60 |
+
.stChatInput textarea::placeholder { color:white }
|
61 |
+
|
62 |
+
|
63 |
+
.stChatInput textarea:focus { border : 1px solid #519ba7; color:white }
|
64 |
+
|
65 |
+
|
66 |
</style>
|
67 |
""",
|
68 |
unsafe_allow_html=True,
|