fabrioop commited on
Commit
18ea130
·
verified ·
1 Parent(s): 83c224c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -1,29 +1,30 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForCausalLM
3
 
4
- modelo = "tu_usuario/mi-ia-chatbot" # tu modelo subido
5
- tokenizer = AutoTokenizer.from_pretrained(modelo)
6
- model = AutoModelForCausalLM.from_pretrained(modelo)
7
 
8
  def responder(mensaje, historial):
9
- if historial is None:
10
- historial = []
11
-
12
- entradas = tokenizer.encode(mensaje + tokenizer.eos_token, return_tensors="pt")
13
- salida = model.generate(
14
- entradas,
15
- max_length=150,
16
- pad_token_id=tokenizer.eos_token_id,
17
- temperature=0.7,
18
- top_p=0.9
19
- )
20
- respuesta = tokenizer.decode(salida[:, entradas.shape[-1]:][0], skip_special_tokens=True)
21
  historial.append((mensaje, respuesta))
22
  return historial, historial
23
 
24
- demo = gr.Blocks()
25
- with demo:
26
- chat = gr.Chatbot()
27
- entrada = gr.Textbox()
28
- entrada.submit(responder, [entrada, chat], [chat, chat])
 
 
 
 
 
 
 
 
 
 
 
 
29
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Modelos de texto e imagen
5
+ chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct", device_map="auto")
6
+ image_gen = pipeline("text-to-image", model="stabilityai/stable-diffusion-2")
7
 
8
  def responder(mensaje, historial):
9
+ respuesta = chatbot(mensaje, max_new_tokens=200, temperature=0.7)[0]["generated_text"]
 
 
 
 
 
 
 
 
 
 
 
10
  historial.append((mensaje, respuesta))
11
  return historial, historial
12
 
13
+ def generar_imagen(prompt):
14
+ imagen = image_gen(prompt)[0]["image"]
15
+ return imagen
16
+
17
+ with gr.Blocks() as demo:
18
+ gr.Markdown("# 🤖 Mi IA Chat + Imagen")
19
+
20
+ with gr.Tab("💬 Chat"):
21
+ chat = gr.Chatbot()
22
+ entrada = gr.Textbox()
23
+ entrada.submit(responder, [entrada, chat], [chat, chat])
24
+
25
+ with gr.Tab("🎨 Imagen"):
26
+ prompt = gr.Textbox(label="Escribe lo que quieres ver")
27
+ salida = gr.Image()
28
+ prompt.submit(generar_imagen, inputs=prompt, outputs=salida)
29
+
30
  demo.launch()