Spaces:
No application file
No application file
| # app.py – 13 kategorideki önerilen modelleri tek ekranda çalıştırır | |
| import gradio as gr | |
| from transformers import pipeline | |
| import torch | |
| # ---------- 1) TEXT GENERATION ---------- | |
| gen_pipe = pipeline("text-generation", model="WiroAI/wiroai-turkish-llm-9b", device_map="auto") | |
| # ---------- 2) TEXT CLASSIFICATION ---------- | |
| cls_pipe = pipeline("text-classification", model="savasy/bert-base-turkish-sentiment-cased") | |
| # ---------- 3) TOKEN CLASSIFICATION (NER) ---------- | |
| ner_pipe = pipeline("token-classification", model="akdeniz27/bert-base-turkish-cased-ner", | |
| aggregation_strategy="simple") | |
| # ---------- 4) FILL-MASK ---------- | |
| mask_pipe = pipeline("fill-mask", model="dbmdz/bert-base-turkish-uncased") | |
| # ---------- 5) QUESTION ANSWERING ---------- | |
| qa_pipe = pipeline("question-answering", model="emrecan/bert-base-turkish-cased-squad") | |
| # ---------- 6) SUMMARIZATION ---------- | |
| summ_pipe = pipeline("summarization", model="mrm8488/bert2bert_shared-turkish-summarization") | |
| # ---------- 7) TRANSLATION ---------- | |
| trans_pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-trk-en") | |
| # ---------- 8) TEXT2TEXT GENERATION ---------- | |
| t2t_pipe = pipeline("text2text-generation", model="google/flan-t5-xl") | |
| # ---------- 9) SENTENCE SIMILARITY ---------- | |
| from sentence_transformers import SentenceTransformer, util | |
| sim_model = SentenceTransformer('emrecan/bert-base-turkish-cased-mean-nli-stsb-tr') | |
| # ---------- 10) AUDIO CLASSIFICATION ---------- | |
| # (CPU/GPU uygunluğu için küçük model) | |
| audio_cls_pipe = pipeline("audio-classification", model="superb/wav2vec2-base-superb-ks") | |
| # ---------- 11) AUTOMATIC SPEECH RECOGNITION (ASR) ---------- | |
| asr_pipe = pipeline("automatic-speech-recognition", model="mpoyraz/wav2vec2-xls-r-300m-cv7-turkish") | |
| # ---------- 12) IMAGE-TEXT-TO-TEXT ---------- | |
| # Placeholder: Türkçe VLM örneği | |
| from transformers import BlipProcessor, BlipForConditionalGeneration | |
| from PIL import Image | |
| processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base") | |
| blip_model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base") | |
| # ---------- 13) ZERO-SHOT IMAGE CLASSIFICATION ---------- | |
| zs_pipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch32") | |
| # ---------- GRADIO ARAYÜZ ---------- | |
| def run_task(task, text=None, context=None, audio=None, image=None, src_lang=None, tgt_lang=None, | |
| sentences=None): | |
| if task == "Text Generation": | |
| return gen_pipe(text, max_new_tokens=256)[0]["generated_text"] | |
| elif task == "Text Classification": | |
| return cls_pipe(text)[0] | |
| elif task == "NER": | |
| return ner_pipe(text) | |
| elif task == "Fill-Mask": | |
| return mask_pipe(text) | |
| elif task == "Question Answering": | |
| return qa_pipe(question=text, context=context) | |
| elif task == "Summarization": | |
| return summ_pipe(text)[0]["summary_text"] | |
| elif task == "Translation": | |
| return trans_pipe(text)[0]["translation_text"] | |
| elif task == "Text2Text": | |
| return t2t_pipe(text)[0]["generated_text"] | |
| elif task == "Sentence Similarity": | |
| emb1 = sim_model.encode(sentences[0]) | |
| emb2 = sim_model.encode(sentences[1]) | |
| return float(util.cos_sim(emb1, emb2)) | |
| elif task == "Audio Classification" and audio is not None: | |
| return audio_cls_pipe(audio) | |
| elif task == "ASR" and audio is not None: | |
| return asr_pipe(audio)["text"] | |
| elif task == "Image Caption" and image is not None: | |
| inputs = processor(image, return_tensors="pt") | |
| out = blip_model.generate(**inputs) | |
| return processor.decode(out[0], skip_special_tokens=True) | |
| elif task == "Zero-Shot Image" and image is not None: | |
| labels = ["cat", "dog", "car", "person"] | |
| return zs_pipe(image, candidate_labels=labels) | |
| else: | |
| return "Lütfen görev için gerekli girdileri sağlayın." | |
| demo = gr.Interface( | |
| fn=run_task, | |
| inputs=[ | |
| gr.Dropdown( | |
| ["Text Generation", "Text Classification", "NER", "Fill-Mask", | |
| "Question Answering", "Summarization", "Translation", | |
| "Text2Text", "Sentence Similarity", "Audio Classification", | |
| "ASR", "Image Caption", "Zero-Shot Image"], | |
| label="Görev Seç"), | |
| gr.Textbox(placeholder="Metin girin...", label="Metin"), | |
| gr.Textbox(placeholder="Bağlam (QA için)", label="Bağlam", visible=False), | |
| gr.Audio(type="filepath", label="Ses Dosyası"), | |
| gr.Image(type="pil", label="Görsel"), | |
| ], | |
| outputs=gr.JSON(label="Sonuç"), | |
| title="Engelsiz-AI", | |
| description="Tüm görevler için tek ekran: Türkçe destekli 13 farklı modeli tek yerde kullanın." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |