Spaces:
Sleeping
Sleeping
commit
Browse files- commit.py +36 -0
- requirements.txt +3 -0
commit.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
"""
|
| 4 |
+
Created on Thu Apr 17 20:18:35 2025
|
| 5 |
+
|
| 6 |
+
@author: rick
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import gradio as gr
|
| 10 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 11 |
+
|
| 12 |
+
model_id = "mistralai/Mistral-7B-Instruct-v0.1"
|
| 13 |
+
|
| 14 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 15 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 16 |
+
model_id,
|
| 17 |
+
device_map="auto",
|
| 18 |
+
torch_dtype="auto",
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 22 |
+
|
| 23 |
+
def generar_commit(diff):
|
| 24 |
+
prompt = f"Escribí un mensaje de commit claro, corto y técnico basado en los siguientes cambios:\n{diff}"
|
| 25 |
+
output = pipe(prompt, max_new_tokens=60, do_sample=True, temperature=0.7)
|
| 26 |
+
return output[0]["generated_text"]
|
| 27 |
+
|
| 28 |
+
demo = gr.Interface(
|
| 29 |
+
fn=generar_commit,
|
| 30 |
+
inputs=gr.Textbox(lines=10, label="Código diff"),
|
| 31 |
+
outputs="text",
|
| 32 |
+
title="🤖 Commit Generator",
|
| 33 |
+
description="Pega aquí tus cambios (git diff) y generá un mensaje de commit automático.",
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
torch
|
| 3 |
+
gradio
|