Spaces:
Sleeping
Sleeping
File size: 1,287 Bytes
a93fcd0 c14dcf3 a93fcd0 c14dcf3 a93fcd0 83dca78 a93fcd0 c14dcf3 83dca78 c14dcf3 a93fcd0 c14dcf3 a93fcd0 c14dcf3 |
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 37 38 39 40 |
import gradio as gr
import requests
import os
HF_API_TOKEN = os.getenv("HF_API_TOKEN")
API_URL = "https://api-inference.huggingface.co/models/datificate/gpt2-small-spanish"
headers = {}
def accionar_ai(pregunta):
prompt = f"""
Soy Accionar AI, una herramienta digital que apoya a activistas, colectivas y movimientos sociales de América Latina.
Cuando alguien me escribe una idea o pregunta, les doy sugerencias claras para empezar una campaña con enfoque de derechos humanos, justicia climática, feminismos o participación ciudadana.
Pregunta: {pregunta}
Sugerencia:
"""
payload = {
"inputs": prompt,
"parameters": {"max_new_tokens": 150, "temperature": 0.7},
}
response = requests.post(API_URL, headers=headers, json=payload)
result = response.json()
if isinstance(result, list):
return result[0]["generated_text"].split("Sugerencia:")[-1].strip()
else:
return "Lo siento, hubo un error al generar la respuesta."
# Interfaz Gradio
demo = gr.Interface(
fn=accionar_ai,
inputs=gr.Textbox(lines=3, placeholder="Escribe tu pregunta o idea de campaña"),
outputs="text",
title="Accionar AI Commons (Demo real)",
description="Asistente conectado a modelo GPT-Neo desde Hugging Face",
)
demo.launch()
|