Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
| 3 |
|
|
|
|
| 4 |
model = AutoModelForSequenceClassification.from_pretrained("savasy/bert-base-turkish-sentiment-cased")
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("savasy/bert-base-turkish-sentiment-cased")
|
| 6 |
|
|
|
|
|
|
|
| 7 |
def greet(text):
|
| 8 |
-
|
| 9 |
-
return
|
| 10 |
-
|
| 11 |
-
iface = gr.Interface(
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
| 3 |
|
| 4 |
+
# Model ve tokenizer bir kere yükleniyor (performans için önemli)
|
| 5 |
model = AutoModelForSequenceClassification.from_pretrained("savasy/bert-base-turkish-sentiment-cased")
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained("savasy/bert-base-turkish-sentiment-cased")
|
| 7 |
|
| 8 |
+
sentiment_pipe = pipeline("sentiment-analysis", tokenizer=tokenizer, model=model)
|
| 9 |
+
|
| 10 |
def greet(text):
|
| 11 |
+
result = sentiment_pipe(text)[0]['label']
|
| 12 |
+
return result
|
| 13 |
+
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=greet,
|
| 16 |
+
inputs=gr.Textbox(placeholder="Lütfen Cümle Giriniz...", lines=5),
|
| 17 |
+
outputs=gr.Textbox(label="Duygu Analizi Sonucu")
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
iface.launch()
|