Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import torch | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| # Cargar modelo y tokenizer | |
| model_name = "MorcuendeA/MulderFinders" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForSequenceClassification.from_pretrained(model_name, trust_remote_code=True) | |
| # Función de clasificación personalizada | |
| def classify_text(text): | |
| if not text.strip(): | |
| return {"Error": 1.0} | |
| try: | |
| inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512) | |
| outputs = model(**inputs) | |
| logits = outputs.logits | |
| probs = torch.softmax(logits, dim=1)[0] | |
| labels = model.config.id2label | |
| return {labels[i]: float(probs[i]) for i in range(len(probs))} | |
| except Exception as e: | |
| return {"Error": 1.0} | |
| # gr.Interface | |
| demo = gr.Interface( | |
| fn=classify_text, | |
| inputs=gr.Textbox( | |
| label="Introduce la epifanía tuitera", | |
| placeholder="¿Qué gran verdad quieres revelar?...", | |
| lines=4 | |
| ), | |
| outputs=gr.Label(label="Resultado de la clasificación"), | |
| title="🛸 Clasificador de iluminados - MulderFinders", | |
| description=""" | |
| <img src="https://huggingface.co/MorcuendeA/MulderFinders/resolve/main/i_want_to_belive.png" width="600"> | |
| """, | |
| examples=[ | |
| ["Nos mienten sobre los ovnis. ¿Por qué tanto secreto?"], | |
| ["Las vacunas tienen microchips. Nos quieren controlar. Abran los ojos. #Despierta"], | |
| ["Mucho ruido sobre ovnis, pero cero evidencia verificable. La hipótesis extraterrestre sigue siendo solo eso: una hipótesis. #STOPbulos"], | |
| ["Correlación no implica causalidad"] | |
| ], | |
| theme=gr.themes.Soft(), | |
| allow_flagging="never" | |
| ) | |
| # Lanza la app | |
| if __name__ == "__main__": | |
| demo.launch() |