QnoM's picture
Update app.py
b07f454 verified
Raw History Blame Contribute Delete
1.42 kB
import gradio as gr
import os
# Ajouter un chemin statique
static_dir = os.path.abspath("/img") # Chemin vers le répertoire actuel contenant `ascii_image.png`
gr.set_static_paths(static_dir)
def load():
# Retourne des paires texte + HTML pour le Chatbot
return [
("Here's an audio", "<audio controls><source src='https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample.wav'></audio>"),
("Here's a video", "<video controls width='300'><source src='https://github.com/gradio-app/gradio/raw/main/demo/video_component/files/world.mp4'></video>"),
("Here's an image", "<img src='https://emmanuelmancuso.com/portfolio/static/img/ASCII-art.png' width='300' />"),
("Here's an image", "<img src='/file=ascii_image.png' width='300' />")
]
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
button = gr.Button("Load audio, video, and image")
def update_chatbot():
# Récupère les éléments et les formate correctement pour le Chatbot
data = load()
chat_history = []
for message, content in data:
# Combine texte et contenu HTML dans la même bulle
combined_message = f"{message}{content}"
chat_history.append(("", combined_message)) # "" pour l'utilisateur, réponse pour le bot
return chat_history
button.click(update_chatbot, inputs=None, outputs=chatbot)
demo.launch()