Download app.py from Mariano90/cvitae: direct link, hf CLI and curl.
- Browser
- Download file 2.33 kB
-
https://huggingface.co/spaces/Mariano90/cvitae/resolve/main/app.py
- Command line
-
hf download hf://spaces/Mariano90/cvitae/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Mariano90/cvitae/resolve/main/app.py
2.33 kB
| import gradio as gr | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline | |
| # --------------------------- | |
| # MODELO LIGERO PARA CHAT | |
| # --------------------------- | |
| model_name = "TheBloke/guanaco-7B-GPTQ" # Conversacional, rápido y gratuito | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForCausalLM.from_pretrained(model_name) | |
| chat_pipe = pipeline("text-generation", model=model, tokenizer=tokenizer) | |
| # --------------------------- | |
| # CV RESUMIDO | |
| # --------------------------- | |
| with open("cv.txt", "r", encoding="utf-8") as f: | |
| cv_text = f.read() | |
| # --------------------------- | |
| # FUNCION DE RESPUESTA | |
| # --------------------------- | |
| def responder(pregunta): | |
| prompt = f""" | |
| Usa solo la información de este CV para responder en español, primera persona, de forma breve y profesional. | |
| Pregunta: {pregunta} | |
| CV: | |
| {cv_text} | |
| """ | |
| respuesta = chat_pipe(prompt, max_length=200, do_sample=False)[0]['generated_text'] | |
| return respuesta | |
| # --------------------------- | |
| # INTERFAZ GRADIO | |
| # --------------------------- | |
| with gr.Blocks() as demo: | |
| # Imagen inicial | |
| gr.Image(value="marianobot.png", interactive=False) | |
| # Título grande del chat | |
| gr.Markdown("<h2>🤖 MarianoBot – ¡Descubre y pregunta todo lo que quieras!</h2>", elem_id="titulo") | |
| # Chatbot con saludo inicial | |
| chatbot = gr.Chatbot(type="messages", value=[{"role":"assistant","content":"¡Hola! ¡Pregúntame para conocer más sobre mí!"}]) | |
| # Entrada de pregunta | |
| question_input = gr.Textbox( | |
| label="Escribe tu pregunta...", | |
| placeholder="Pregunta sobre mi experiencia, habilidades o trayectoria", | |
| lines=1 | |
| ) | |
| # Botón enviar | |
| submit_button = gr.Button("Hacer pregunta", elem_id="boton-naranja") | |
| # Función para actualizar el chat | |
| def enviar(input_text, history): | |
| answer = responder(input_text) | |
| history.append({"role":"user","content":input_text}) | |
| history.append({"role":"assistant","content":answer}) | |
| return history, "" | |
| # Conectar textbox y botón | |
| question_input.submit(enviar, [question_input, chatbot], [chatbot, question_input]) | |
| submit_button.click(enviar, [question_input, chatbot], [chatbot, question_input]) | |
| # --------------------------- | |
| # LANZAR INTERFAZ | |
| # --------------------------- | |
| demo.launch() | |