Spaces:
Sleeping
Sleeping
| 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() | |