Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,53 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
model = AutoModelForSequenceClassification.from_pretrained(
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
| 3 |
|
| 4 |
+
# Modeli 1 kez yükle (hız için)
|
| 5 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
| 6 |
+
"savasy/bert-base-turkish-sentiment-cased"
|
| 7 |
+
)
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 9 |
+
"savasy/bert-base-turkish-sentiment-cased"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
sentiment_pipe = pipeline(
|
| 13 |
+
"sentiment-analysis",
|
| 14 |
+
tokenizer=tokenizer,
|
| 15 |
+
model=model
|
| 16 |
+
)
|
| 17 |
|
| 18 |
+
def analyze(text):
|
| 19 |
+
result = sentiment_pipe(text)[0]["label"]
|
| 20 |
+
if result == "positive":
|
| 21 |
+
return "🔵 POZİTİF"
|
| 22 |
+
elif result == "negative":
|
| 23 |
+
return "🔴 NEGATİF"
|
| 24 |
+
else:
|
| 25 |
+
return "🟡 NÖTR"
|
| 26 |
|
| 27 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 28 |
+
gr.Markdown(
|
| 29 |
+
"""
|
| 30 |
+
# 🇹🇷 Türkçe Duygu Analizi
|
| 31 |
+
BERT tabanlı Türkçe cümle analiz modeli
|
| 32 |
+
|
| 33 |
+
Bir cümle yaz → Model sana **POZİTİF / NEGATİF / NÖTR** sonucunu söylesin.
|
| 34 |
+
"""
|
| 35 |
+
)
|
| 36 |
|
| 37 |
+
with gr.Row():
|
| 38 |
+
text_input = gr.Textbox(
|
| 39 |
+
label="Cümle",
|
| 40 |
+
placeholder="Bir cümle yazınız...",
|
| 41 |
+
lines=4
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
analyze_button = gr.Button("Analiz Et")
|
| 45 |
+
|
| 46 |
+
output = gr.Textbox(
|
| 47 |
+
label="Duygu Sonucu",
|
| 48 |
+
interactive=False
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
analyze_button.click(analyze, inputs=text_input, outputs=output)
|
| 52 |
|
| 53 |
+
demo.launch()
|