Download app.py from Katake/sunum: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/Katake/sunum/resolve/main/app.py
- Command line
-
hf download hf://spaces/Katake/sunum/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Katake/sunum/resolve/main/app.py
1.15 kB
| import gradio as gr | |
| from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline | |
| # Modeli tek sefer yükle | |
| model = AutoModelForSequenceClassification.from_pretrained( | |
| "savasy/bert-base-turkish-sentiment-cased" | |
| ) | |
| tokenizer = AutoTokenizer.from_pretrained( | |
| "savasy/bert-base-turkish-sentiment-cased" | |
| ) | |
| sentiment_pipe = pipeline( | |
| "sentiment-analysis", | |
| tokenizer=tokenizer, | |
| model=model | |
| ) | |
| def analyze(text): | |
| result = sentiment_pipe(text)[0]["label"] | |
| if result == "positive": | |
| return "🔵 POZİTİF" | |
| elif result == "negative": | |
| return "🔴 NEGATİF" | |
| return "🟡 NÖTR" | |
| with gr.Blocks() as demo: | |
| gr.Markdown( | |
| """ | |
| # 🇹🇷 Türkçe Duygu Analizi | |
| Bir cümle yaz → Model sonucu göstersin. | |
| """ | |
| ) | |
| text_input = gr.Textbox( | |
| label="Cümle", | |
| placeholder="Bir cümle yazınız...", | |
| lines=4 | |
| ) | |
| analyze_button = gr.Button("Analiz Et") | |
| output = gr.Textbox( | |
| label="Duygu Sonucu", | |
| interactive=False | |
| ) | |
| analyze_button.click(analyze, inputs=text_input, outputs=output) | |
| demo.launch() | |