Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,95 +1,19 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import json
|
| 3 |
-
import pyttsx3 # Pour faire parler l'IA
|
| 4 |
-
|
| 5 |
-
# Charger les données
|
| 6 |
-
def charger_donnees():
|
| 7 |
-
with open("semxflow_data.json", "r", encoding="utf-8") as file:
|
| 8 |
-
return json.load(file)
|
| 9 |
-
|
| 10 |
-
# Répondre et parler
|
| 11 |
-
def chatbot_response(message):
|
| 12 |
-
data = charger_donnees()
|
| 13 |
-
reponses = data.get("reponses", {})
|
| 14 |
-
|
| 15 |
-
# Vérifier si l'IA connaît la réponse
|
| 16 |
-
reponse = reponses.get(message.lower(), "Désolé, je ne comprends pas encore cette question.")
|
| 17 |
-
|
| 18 |
-
# Convertir en audio
|
| 19 |
-
tts = pyttsx3.init()
|
| 20 |
-
tts.say(reponse)
|
| 21 |
-
tts.runAndWait()
|
| 22 |
-
|
| 23 |
-
return reponse
|
| 24 |
-
|
| 25 |
-
# Interface Gradio avec audio
|
| 26 |
-
iface = gr.Interface(
|
| 27 |
-
fn=chatbot_response,
|
| 28 |
-
inputs="text",
|
| 29 |
-
outputs=["text"],
|
| 30 |
-
title="Chatbot SemXFlow",
|
| 31 |
-
description="Pose-moi des questions et je vais répondre (avec la voix bientôt) !"
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
if __name__ == "__main__":
|
| 35 |
-
iface.launch()
|
| 36 |
-
import gradio as gr
|
| 37 |
-
import json
|
| 38 |
-
import pyttsx3 # Pour faire parler l'IA
|
| 39 |
|
| 40 |
# Charger les données
|
| 41 |
def charger_donnees():
|
| 42 |
with open("semxflow_data.json", "r", encoding="utf-8") as file:
|
| 43 |
return json.load(file)
|
| 44 |
|
| 45 |
-
#
|
| 46 |
def chatbot_response(message):
|
| 47 |
data = charger_donnees()
|
| 48 |
reponses = data.get("reponses", {})
|
| 49 |
|
| 50 |
# Vérifier si l'IA connaît la réponse
|
| 51 |
reponse = reponses.get(message.lower(), "Désolé, je ne comprends pas encore cette question.")
|
| 52 |
-
|
| 53 |
-
#
|
| 54 |
-
tts = pyttsx3.init()
|
| 55 |
-
tts.say(reponse)
|
| 56 |
-
tts.runAndWait()
|
| 57 |
-
|
| 58 |
-
return reponse
|
| 59 |
-
|
| 60 |
-
# Interface Gradio avec audio
|
| 61 |
-
iface = gr.Interface(
|
| 62 |
-
fn=chatbot_response,
|
| 63 |
-
inputs="text",
|
| 64 |
-
outputs=["text"],
|
| 65 |
-
title="Chatbot SemXFlow",
|
| 66 |
-
description="Pose-moi des questions et je vais répondre (avec la voix bientôt) !"
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
if __name__ == "__main__":
|
| 70 |
-
iface.launch()
|
| 71 |
-
import os
|
| 72 |
-
os.system("pip install pyttsx3")
|
| 73 |
-
|
| 74 |
-
import pyttsx3
|
| 75 |
-
engine = pyttsx3.init()
|
| 76 |
-
engine.say("L'installation a réussi !")
|
| 77 |
-
engine.runAndWait()
|
| 78 |
-
import gradio as gr
|
| 79 |
-
from gtts import gTTS
|
| 80 |
-
import os
|
| 81 |
-
|
| 82 |
-
def parler(texte):
|
| 83 |
-
tts = gTTS(text=texte, lang="fr")
|
| 84 |
-
tts.save("output.mp3")
|
| 85 |
-
return "output.mp3"
|
| 86 |
-
|
| 87 |
-
iface = gr.Interface(
|
| 88 |
-
fn=parler,
|
| 89 |
-
inputs="text",
|
| 90 |
-
outputs="audio",
|
| 91 |
-
title="SemXFlow AI - Parle avec moi !",
|
| 92 |
-
description="Écris un texte et écoute l'IA parler."
|
| 93 |
-
)
|
| 94 |
-
|
| 95 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from gtts import gTTS # Google Text-to-Speech
|
| 3 |
+
import os
|
| 4 |
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Charger les données
|
| 7 |
def charger_donnees():
|
| 8 |
with open("semxflow_data.json", "r", encoding="utf-8") as file:
|
| 9 |
return json.load(file)
|
| 10 |
|
| 11 |
+
# Fonction de réponse et de parole
|
| 12 |
def chatbot_response(message):
|
| 13 |
data = charger_donnees()
|
| 14 |
reponses = data.get("reponses", {})
|
| 15 |
|
| 16 |
# Vérifier si l'IA connaît la réponse
|
| 17 |
reponse = reponses.get(message.lower(), "Désolé, je ne comprends pas encore cette question.")
|
| 18 |
+
|
| 19 |
+
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|