Spaces:
Sleeping
Sleeping
Update app.py
Browse filesAPI endpoint eklemesi
app.py
CHANGED
|
@@ -3,10 +3,8 @@ from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
|
| 3 |
import torch
|
| 4 |
import torch.nn.functional as F
|
| 5 |
|
| 6 |
-
#
|
| 7 |
model_name = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
|
| 8 |
-
|
| 9 |
-
# Model ve tokenizer
|
| 10 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 11 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 12 |
|
|
@@ -31,17 +29,28 @@ def analyze_text(text):
|
|
| 31 |
"empty": "💬"
|
| 32 |
}
|
| 33 |
|
| 34 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
fn=analyze_text,
|
| 39 |
-
inputs=gr.Textbox(label="Metin Gir / Enter Text"),
|
| 40 |
-
outputs="json",
|
| 41 |
-
title="🌍 Multilingual Sentiment Analyzer",
|
| 42 |
-
description="Analyzes text sentiment in multiple languages (English, Turkish, etc.)",
|
| 43 |
-
)
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
iface.launch(server_name="0.0.0.0", server_port=7860) # artık enable_queue yok
|
|
|
|
| 3 |
import torch
|
| 4 |
import torch.nn.functional as F
|
| 5 |
|
| 6 |
+
# Model
|
| 7 |
model_name = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
|
|
|
|
|
|
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 10 |
|
|
|
|
| 29 |
"empty": "💬"
|
| 30 |
}
|
| 31 |
|
| 32 |
+
return {
|
| 33 |
+
"label": top_label,
|
| 34 |
+
"emoji": emoji_map[top_label],
|
| 35 |
+
"scores": scores
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
# ✅ API olarak çalışan bir endpoint
|
| 39 |
+
def api_predict(text: str):
|
| 40 |
+
result = analyze_text(text)
|
| 41 |
+
return result
|
| 42 |
+
|
| 43 |
+
with gr.Blocks() as demo:
|
| 44 |
+
gr.Markdown("## 🌍 Multilingual Sentiment Analyzer")
|
| 45 |
+
|
| 46 |
+
with gr.Row():
|
| 47 |
+
input_text = gr.Textbox(label="Metin")
|
| 48 |
+
output_json = gr.JSON(label="Sonuç")
|
| 49 |
+
|
| 50 |
+
input_text.change(fn=analyze_text, inputs=input_text, outputs=output_json)
|
| 51 |
|
| 52 |
+
# ✅ API endpoint: /api/predict
|
| 53 |
+
demo.add_api_route("/api/predict", api_predict, methods=["POST"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
demo.queue()
|
| 56 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|