Spaces:
Sleeping
Sleeping
File size: 1,112 Bytes
cc67875 79b1ec9 cc67875 b946173 79b1ec9 cc67875 79b1ec9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import os
import requests
HUGGINGFACE_API_TOKEN = os.environ.get("HF_TOKEN", "")
API_URL = "https://api-inference.huggingface.co/models/huggingface/CodeBERTa-language-id"
headers = {
"Authorization": f"Bearer {HUGGINGFACE_API_TOKEN}"
}
def obtener_sugerencia_nlp(texto_comentario):
payload = {
"inputs": f"// {texto_comentario}\n# sugerido:",
"parameters": {
"max_new_tokens": 20,
"temperature": 0.7,
"return_full_text": False
}
}
response = requests.post(API_URL, headers=headers, json=payload)
if response.status_code == 200:
resultado = response.json()
return resultado[0]["generated_text"].strip()
else:
return f"(sin sugerencia: {response.status_code})"
def procesar_comentarios(codigo: str):
lineas = codigo.splitlines()
sugerencias = []
for linea in lineas:
if "//" in linea:
comentario = linea.split("//", 1)[1].strip()
sugerencia = obtener_sugerencia_nlp(comentario)
sugerencias.append((comentario, sugerencia))
return sugerencias |