Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline | |
| model_id = "microsoft/phi-1_5" # modelo 100% libre | |
| # Carga del modelo sin device_map ni dtype | |
| tokenizer = AutoTokenizer.from_pretrained(model_id) | |
| model = AutoModelForCausalLM.from_pretrained(model_id) | |
| # Crear pipeline | |
| pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, return_full_text=False) | |
| # Funci贸n para generar commit | |
| def generar_commit(diff): | |
| prompt = f"Escrib铆 solo el mensaje de commit para el siguiente cambio de c贸digo:\n{diff}" | |
| output = pipe(prompt, max_new_tokens=40, do_sample=True, temperature=0.7) | |
| return [output[0]["generated_text"]] | |
| # Interfaz Gradio | |
| 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() |