Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,14 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
-
import torch
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_auth_token=True)
|
| 8 |
-
model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME, use_auth_token=True)
|
| 9 |
|
| 10 |
-
# Sentiment analizi fonksiyonu
|
| 11 |
def analyze_sentiment(text):
|
| 12 |
-
|
| 13 |
-
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
outputs = model(**inputs)
|
| 18 |
-
|
| 19 |
-
# Modelin çıktısını al (logits)
|
| 20 |
-
logits = outputs.logits
|
| 21 |
-
predicted_class = torch.argmax(logits, dim=-1).item()
|
| 22 |
-
|
| 23 |
-
# Sentiment sınıfını belirle
|
| 24 |
-
if predicted_class == 0:
|
| 25 |
-
return "Negative"
|
| 26 |
-
elif predicted_class == 1:
|
| 27 |
-
return "Neutral"
|
| 28 |
-
else:
|
| 29 |
-
return "Positive"
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
iface
|
| 33 |
-
inputs="text",
|
| 34 |
-
outputs="text",
|
| 35 |
-
title="Financial Sentiment Analysis",
|
| 36 |
-
description="Enter a financial text, and the model will analyze its sentiment (Positive, Neutral, or Negative).")
|
| 37 |
-
|
| 38 |
-
# Uygulamayı başlat
|
| 39 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
+
# DistilBERT modelini yükle
|
| 5 |
+
model = pipeline("sentiment-analysis", model="distilbert-base-uncased")
|
|
|
|
|
|
|
| 6 |
|
|
|
|
| 7 |
def analyze_sentiment(text):
|
| 8 |
+
return model(text)
|
|
|
|
| 9 |
|
| 10 |
+
# Gradio arayüzünü oluştur
|
| 11 |
+
iface = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="json")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# CPU üzerinde çalışacak şekilde başlat
|
| 14 |
+
iface.launch(share=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|