Cihat Emre
commited on
Commit
·
5de9868
0
Parent(s):
Initial commit
Browse files- .gitignore +23 -0
- app.py +45 -0
- requirements.txt +3 -0
.gitignore
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Sanal ortam klasörü
|
| 2 |
+
venv/
|
| 3 |
+
|
| 4 |
+
# Python derleme dosyaları
|
| 5 |
+
__pycache__/
|
| 6 |
+
*.py[cod]
|
| 7 |
+
*.pyo
|
| 8 |
+
*.pyd
|
| 9 |
+
|
| 10 |
+
# IDE ve editör dosyaları
|
| 11 |
+
.vscode/
|
| 12 |
+
.idea/
|
| 13 |
+
.DS_Store
|
| 14 |
+
|
| 15 |
+
# Log ve geçici dosyalar
|
| 16 |
+
*.log
|
| 17 |
+
*.tmp
|
| 18 |
+
|
| 19 |
+
# Jupyter notebook checkpointleri
|
| 20 |
+
.ipynb_checkpoints/
|
| 21 |
+
|
| 22 |
+
# Diğer
|
| 23 |
+
.env
|
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from textblob import TextBlob
|
| 4 |
+
from deep_translator import GoogleTranslator
|
| 5 |
+
|
| 6 |
+
def sentiment_analysis(text: str) -> str:
|
| 7 |
+
"""
|
| 8 |
+
Türkçe metni İngilizce'ye çevirip, İngilizce metin üzerinden duygu analizi yapar.
|
| 9 |
+
"""
|
| 10 |
+
try:
|
| 11 |
+
eng_text = GoogleTranslator(source='tr', target='en').translate(text)
|
| 12 |
+
except Exception as e:
|
| 13 |
+
return json.dumps({"hata": f"Çeviri hatası: {str(e)}"})
|
| 14 |
+
|
| 15 |
+
blob = TextBlob(eng_text)
|
| 16 |
+
sentiment = blob.sentiment
|
| 17 |
+
|
| 18 |
+
# Değerleri Türkçeleştir
|
| 19 |
+
if sentiment.polarity > 0:
|
| 20 |
+
assessment = "pozitif"
|
| 21 |
+
elif sentiment.polarity < 0:
|
| 22 |
+
assessment = "negatif"
|
| 23 |
+
else:
|
| 24 |
+
assessment = "nötr"
|
| 25 |
+
|
| 26 |
+
sonuc = {
|
| 27 |
+
"duygu_puani": round(sentiment.polarity, 2), # -1 (negatif) ile 1 (pozitif) arası
|
| 28 |
+
"öznelik": round(sentiment.subjectivity, 2), # 0 (nesnel) ile 1 (öznel) arası
|
| 29 |
+
"degerlendirme": assessment
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
return json.dumps(sonuc, ensure_ascii=False)
|
| 33 |
+
|
| 34 |
+
# Create the Gradio interface
|
| 35 |
+
demo = gr.Interface(
|
| 36 |
+
fn=sentiment_analysis,
|
| 37 |
+
inputs=gr.Textbox(placeholder="Türkçe metin girin..."),
|
| 38 |
+
outputs=gr.Textbox(),
|
| 39 |
+
title="Türkçe Metin Duygu Analizi",
|
| 40 |
+
description="TextBlob ve otomatik çeviri ile Türkçe metinlerde duygu analizi yapar."
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
# Launch the interface and MCP server
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
demo.launch(mcp_server=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
textblob
|
| 3 |
+
deep-translator
|