Mariano90 commited on
Commit
2d866b2
·
verified ·
1 Parent(s): 9e4de62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -30
app.py CHANGED
@@ -2,21 +2,16 @@ import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
3
 
4
  # ---------------------------
5
- # CONFIGURACIÓN DEL MODELO
6
  # ---------------------------
7
  model_name = "google/flan-t5-small"
8
-
9
  tokenizer = AutoTokenizer.from_pretrained(model_name)
10
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
11
 
12
- qa_pipeline = pipeline(
13
- "text2text-generation",
14
- model=model,
15
- tokenizer=tokenizer
16
- )
17
 
18
  # ---------------------------
19
- # CARGAR CV
20
  # ---------------------------
21
  with open("cv.txt", "r", encoding="utf-8") as f:
22
  cv_text = f.read()
@@ -26,11 +21,11 @@ with open("cv.txt", "r", encoding="utf-8") as f:
26
  # ---------------------------
27
  def answer_question(question):
28
  prompt = (
29
- f"Usa SOLO la información del CV proporcionado para responder la pregunta. "
30
  f"En español, primera persona, breve y profesional. No inventes datos.\n\n"
31
  f"Pregunta: {question}\n\nCV:\n{cv_text}"
32
  )
33
- response = qa_pipeline(prompt, max_length=300, do_sample=False)
34
  return response[0]['generated_text']
35
 
36
  # ---------------------------
@@ -38,45 +33,39 @@ def answer_question(question):
38
  # ---------------------------
39
  with gr.Blocks() as demo:
40
 
 
 
 
41
  # Título del chat
42
  gr.Markdown("## 🤖 MarianoBot – ¡Descubre y pregunta todo lo que quieras!")
43
 
44
- # Imagen + saludo inicial
45
  chatbot = gr.Chatbot(
46
  value=[
47
- [
48
- None,
49
- "![MarianoBot](file/marianobot.png)\n\n👋 ¡Hola! Soy MarianoBot y estoy listo para que me preguntes."
50
- ]
51
- ],
52
- label="Chat de Mariano"
53
  )
54
 
55
  # Entrada de texto
56
  question_input = gr.Textbox(
57
  label="Escribe tu pregunta...",
58
- placeholder="Pregunta sobre mi experiencia, habilidades o trayectoria"
 
59
  )
60
 
61
- # Botones de preguntas frecuentes (opcionales)
62
- with gr.Row():
63
- btn1 = gr.Button("¿Cuántos años de experiencia tienes en marketing?")
64
- btn2 = gr.Button("¿Cuál es tu experiencia en SEO y SEM?")
65
- btn3 = gr.Button("Háblame de tus hobbies")
66
 
67
- # Función para actualizar chatbot
68
  def submit_question(user_input, history):
69
  answer = answer_question(user_input)
70
  history = history + [[user_input, answer]]
71
  return history, ""
72
 
73
- # Conectar la entrada de texto
74
  question_input.submit(submit_question, [question_input, chatbot], [chatbot, question_input])
75
-
76
- # Conectar botones de ejemplo
77
- btn1.click(lambda: submit_question("¿Cuántos años de experiencia tienes en marketing?", chatbot.value), None, [chatbot, question_input])
78
- btn2.click(lambda: submit_question("¿Cuál es tu experiencia en SEO y SEM?", chatbot.value), None, [chatbot, question_input])
79
- btn3.click(lambda: submit_question("Háblame de tus hobbies", chatbot.value), None, [chatbot, question_input])
80
 
81
  # ---------------------------
82
  # INICIAR INTERFAZ
 
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
3
 
4
  # ---------------------------
5
+ # MODELO FLAN-T5
6
  # ---------------------------
7
  model_name = "google/flan-t5-small"
 
8
  tokenizer = AutoTokenizer.from_pretrained(model_name)
9
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
10
 
11
+ qa_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
 
 
 
 
12
 
13
  # ---------------------------
14
+ # CARGAR CV RESUMIDO
15
  # ---------------------------
16
  with open("cv.txt", "r", encoding="utf-8") as f:
17
  cv_text = f.read()
 
21
  # ---------------------------
22
  def answer_question(question):
23
  prompt = (
24
+ f"Usa solo la información de este CV resumido para responder. "
25
  f"En español, primera persona, breve y profesional. No inventes datos.\n\n"
26
  f"Pregunta: {question}\n\nCV:\n{cv_text}"
27
  )
28
+ response = qa_pipeline(prompt, max_length=200, do_sample=False)
29
  return response[0]['generated_text']
30
 
31
  # ---------------------------
 
33
  # ---------------------------
34
  with gr.Blocks() as demo:
35
 
36
+ # Imagen inicial
37
+ gr.Image(value="marianobot.png", interactive=False)
38
+
39
  # Título del chat
40
  gr.Markdown("## 🤖 MarianoBot – ¡Descubre y pregunta todo lo que quieras!")
41
 
42
+ # Chatbot con saludo inicial
43
  chatbot = gr.Chatbot(
44
  value=[
45
+ [None, "¡Hola! ¡Pregúntame para conocer más sobre mí!"]
46
+ ]
 
 
 
 
47
  )
48
 
49
  # Entrada de texto
50
  question_input = gr.Textbox(
51
  label="Escribe tu pregunta...",
52
+ placeholder="Pregunta sobre mi experiencia, habilidades o trayectoria",
53
+ lines=1
54
  )
55
 
56
+ # Botón enviar en color naranja
57
+ submit_button = gr.Button("Hacer pregunta")
58
+ submit_button.style(button_color="#F89651")
 
 
59
 
60
+ # Función para actualizar el chatbot
61
  def submit_question(user_input, history):
62
  answer = answer_question(user_input)
63
  history = history + [[user_input, answer]]
64
  return history, ""
65
 
66
+ # Conectar la entrada de texto y el botón
67
  question_input.submit(submit_question, [question_input, chatbot], [chatbot, question_input])
68
+ submit_button.click(submit_question, [question_input, chatbot], [chatbot, question_input])
 
 
 
 
69
 
70
  # ---------------------------
71
  # INICIAR INTERFAZ