Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import pipeline | |
| import random | |
| TASK_MODELS = { | |
| "Text Classification": [ | |
| "savasy/bert-base-turkish-text-classification", | |
| "GosamaIKU/bert-topic-classification-turkish", | |
| "pamu-tar/bert-turkish-news" | |
| ], | |
| "Translation": [ | |
| "Helsinki-NLP/opus-mt-tr-en", | |
| "asafaya/kanarya-2b", | |
| "boun-tabi-LMG/TURNA" | |
| ], | |
| "Summarization": [ | |
| "Ali-Akbar/summarizer-tr", | |
| "ozcangundes/mt5-small-turkish-summarization", | |
| "RegenAI/umt5-small-turkish-summary" | |
| ], | |
| "Question Answering": [ | |
| "savasy/bert-base-turkish-squad", | |
| "Rustamshry/Qwen2.5-3B-Self-Instruct-Turkish", | |
| "cuneytkaya/fine-tuned-t5-small-turkish-mmlu" | |
| ], | |
| "Text Generation": [ | |
| "dbmdz/gpt2-turkish", | |
| "WiroAI/wiroai-turkish-llm-9b", | |
| "ytu-ce-cosmos/Turkish-Gemma-9b-v0.1" | |
| ], | |
| "Conversational": [ | |
| "merttuerk/CyberYapayZeka-V1", | |
| "asafaya/kanarya-2b", | |
| "mertaydin/phi-turkish" | |
| ], | |
| "Named Entity Recognition": [ | |
| "savasy/bert-base-turkish-ner-cased", | |
| "akdeniz27/bert-base-turkish-cased-ner", | |
| "dbmdz/bert-base-turkish-128k-ner" | |
| ], | |
| "Sentiment Analysis": [ | |
| "savasy/bert-base-turkish-sentiment-cased", | |
| "pamu-tar/bert-turkish-news", | |
| "GosamaIKU/bert-topic-classification-turkish" | |
| ], | |
| "Sentence Similarity": [ | |
| "sentence-transformers/LaBSE", | |
| "paraphrase-multilingual-mpnet-base-v2", | |
| "microsoft/Multilingual-MiniLM-L12-H384" | |
| ], | |
| "Topic Classification": [ | |
| "GosamaIKU/bert-topic-classification-turkish", | |
| "savasy/bert-base-turkish-text-classification", | |
| "pamu-tar/bert-turkish-news" | |
| ], | |
| "Grammar Correction": [ | |
| "metatextgmbh/t5-base-grammar-correction", | |
| "microsoft/trocr-base-handwritten", | |
| "wietsedv/grammar_correction" | |
| ], | |
| "Intent Detection": [ | |
| "muratkavlak/bert-base-turkish-uncased-intent-detection", | |
| "dbmdz/bert-base-turkish-cased", | |
| "savasy/bert-base-turkish-sentiment-cased" | |
| ], | |
| "Token Classification": [ | |
| "savasy/bert-base-turkish-ner-cased", | |
| "akdeniz27/bert-base-turkish-cased-ner", | |
| "dbmdz/bert-base-turkish-128k-ner" | |
| ] | |
| } | |
| def get_random_model(task): | |
| models = TASK_MODELS.get(task, None) | |
| if not models: | |
| return None | |
| return random.choice(models) | |
| def run_task(task, text): | |
| model_name = get_random_model(task) | |
| if model_name is None: | |
| return "Bu görev için model bulunamadı." | |
| if task in ["Text Classification", "Sentiment Analysis", "Topic Classification", "Intent Detection"]: | |
| task_name = "text-classification" | |
| elif task == "Translation": | |
| task_name = "translation" | |
| elif task in ["Summarization", "Grammar Correction"]: | |
| task_name = "summarization" | |
| elif task == "Question Answering": | |
| task_name = "question-answering" | |
| elif task == "Text Generation": | |
| task_name = "text-generation" | |
| elif task == "Conversational": | |
| task_name = "conversational" | |
| elif task in ["Named Entity Recognition", "Token Classification"]: | |
| task_name = "token-classification" | |
| elif task == "Sentence Similarity": | |
| task_name = "feature-extraction" | |
| else: | |
| task_name = "text-generation" | |
| try: | |
| pipe = pipeline(task_name, model=model_name) | |
| except Exception as e: | |
| return f"Model yüklenirken hata: {e}" | |
| try: | |
| if task_name == "question-answering": | |
| context = text | |
| result = pipe(question=text, context=context) | |
| return f"📌 Cevap: {result['answer']} (Model: {model_name})" | |
| elif task_name == "translation": | |
| result = pipe(text) | |
| return f"🌐 Çeviri: {result[0]['translation_text']} (Model: {model_name})" | |
| elif task_name == "summarization": | |
| result = pipe(text) | |
| return f"📝 Özet: {result[0]['summary_text']} (Model: {model_name})" | |
| elif task_name == "text-classification": | |
| result = pipe(text) | |
| labels = ", ".join([f"{r['label']} (%{round(r['score']*100, 2)})" for r in result]) | |
| return f"🧠 Sınıflandırma: {labels} (Model: {model_name})" | |
| elif task_name == "token-classification": | |
| result = pipe(text) | |
| entities = ", ".join([f"{r['entity']}:{r['word']}" for r in result]) | |
| return f"🏷️ Varlık Tanıma: {entities} (Model: {model_name})" | |
| elif task_name == "text-generation": | |
| result = pipe(text, max_new_tokens=50) | |
| return f"✍️ Üretim: {result[0]['generated_text']} (Model: {model_name})" | |
| elif task_name == "conversational": | |
| result = pipe(text) | |
| return f"💬 Konuşma: {result} (Model: {model_name})" | |
| elif task_name == "feature-extraction": | |
| vec = pipe(text) | |
| return f"🔍 Özellik vektörü uzunluğu: {len(vec[0][0])} (Model: {model_name})" | |
| else: | |
| return "Bu görev için işlem tanımlı değil." | |
| except Exception as e: | |
| return f"İşlem sırasında hata: {e}" | |
| def gradio_chat(text, task): | |
| return run_task(task, text) | |
| tasks = list(TASK_MODELS.keys()) | |
| interface = gr.Interface( | |
| fn=gradio_chat, | |
| inputs=[gr.Textbox(lines=4, placeholder="Buraya Türkçe metin yazın..."), gr.Dropdown(choices=tasks, label="Görev Seçin")], | |
| outputs="text", | |
| title="Türkçe Çok Görevli Süper Chatbot", | |
| description="Hugging Face üzerindeki en iyi Türkçe modellerden seçmeli çoklu görevli chatbot." | |
| ) | |
| interface.launch() | |