CoolFace
Apppublic

UmutPatlak/FullStackProject

sourceHugging Facemitupdated 11mo agoView on Hugging Face
0likes
app.py37 linesDownload Raw Back to root
1import gradio as gr2from transformers import pipeline3 4# "sentiment-analysis" (duygu analizi) için bir model yüklüyoruz.5# Bu model (distilbert) hızlı ve popüler bir İngilizce modelidir.6print("Model yükleniyor...")7sentiment_pipeline = pipeline(8    "sentiment-analysis", 9    model="distilbert-base-uncased-finetuned-sst-2-english"10)11print("Model yüklendi.")12 13def analyze_sentiment(text):14    try:15        # Modeli kullanarak analiz yap16        results = sentiment_pipeline(text)17 18        # Çıktı {'label': 'POSITIVE', 'score': 0.999} şeklinde bir liste döner19        # Bize sadece label'ı (etiketi) lazım20        label = results[0]['label']21        return label22 23    except Exception as e:24        # Bir hata olursa yakala ve bildir25        return f"Hata: {str(e)}"26 27# Gradio için bir arayüz ve API oluştur28iface = gr.Interface(29    fn=analyze_sentiment, 30    inputs=gr.Textbox(lines=2, placeholder="Analiz edilecek metni buraya girin..."), 31    outputs="text",32    title="Duygu Analizi API",33    description="Girilen metnin duygu skorunu (POSITIVE/NEGATIVE) döndürür."34)35 36# Uygulamayı çalıştır ve dışarıya aç37iface.launch()