BlaxGTP / app.py
fabrioop's picture
Update app.py
18ea130 verified
raw
history blame
986 Bytes
import gradio as gr
from transformers import pipeline
# Modelos de texto e imagen
chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct", device_map="auto")
image_gen = pipeline("text-to-image", model="stabilityai/stable-diffusion-2")
def responder(mensaje, historial):
respuesta = chatbot(mensaje, max_new_tokens=200, temperature=0.7)[0]["generated_text"]
historial.append((mensaje, respuesta))
return historial, historial
def generar_imagen(prompt):
imagen = image_gen(prompt)[0]["image"]
return imagen
with gr.Blocks() as demo:
gr.Markdown("# πŸ€– Mi IA Chat + Imagen")
with gr.Tab("πŸ’¬ Chat"):
chat = gr.Chatbot()
entrada = gr.Textbox()
entrada.submit(responder, [entrada, chat], [chat, chat])
with gr.Tab("🎨 Imagen"):
prompt = gr.Textbox(label="Escribe lo que quieres ver")
salida = gr.Image()
prompt.submit(generar_imagen, inputs=prompt, outputs=salida)
demo.launch()