Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import torch | |
| import torch.nn.functional as F | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| # HuggingFace repo’sundaki modeli kullan | |
| MODEL_NAME = "eneser/Nasilsin_ai_model" | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME) | |
| model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME) | |
| model.eval() | |
| id2label = model.config.id2label | |
| def predict(text): | |
| if not text.strip(): | |
| return {"error": "Metin girin"} | |
| inputs = tokenizer( | |
| text, | |
| return_tensors="pt", | |
| truncation=True, | |
| padding=True, | |
| max_length=128 | |
| ) | |
| with torch.no_grad(): | |
| logits = model(**inputs).logits | |
| probs = F.softmax(logits, dim=1)[0] | |
| results = {id2label[i]: round(float(probs[i]), 4) for i in range(len(probs))} | |
| best = max(results, key=results.get) | |
| return { | |
| "tahmin": best, | |
| "guven": results[best], | |
| "tum_sonuclar": results | |
| } | |
| demo = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Textbox(lines=4, placeholder="Duygunu anlat..."), | |
| outputs=gr.JSON(), | |
| title="Nasilsin_AI – Türkçe Duygu Analizi" | |
| ) | |
| demo.launch() | |