Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| """ | |
| Created on Thu Apr 17 20:18:35 2025 | |
| @author: rick | |
| """ | |
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline | |
| model_id = "mistralai/Mistral-7B-Instruct-v0.1" | |
| tokenizer = AutoTokenizer.from_pretrained(model_id) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_id, | |
| device_map="auto", | |
| torch_dtype="auto", | |
| ) | |
| pipe = pipeline("text-generation", model=model, tokenizer=tokenizer) | |
| def generar_commit(diff): | |
| prompt = f"Escribí un mensaje de commit claro, corto y técnico basado en los siguientes cambios:\n{diff}" | |
| output = pipe(prompt, max_new_tokens=60, do_sample=True, temperature=0.7) | |
| return [output[0]["generated_text"]] # <-- esta línea es clave | |
| demo = gr.Interface( | |
| fn=generar_commit, | |
| inputs=gr.Textbox(lines=10, label="Código diff"), | |
| outputs="text", | |
| title="🤖 Commit Generator", | |
| description="Pega aquí tus cambios (git diff) y generá un mensaje de commit automático.", | |
| ) | |
| demo.launch() |