Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	| """ | |
| Streamlit UI için modül. | |
| Bu modül, Streamlit kullanarak web arayüzünü oluşturur. | |
| """ | |
| import streamlit as st | |
| import os | |
| from typing import Dict, Any, Optional | |
| # Kendi modüllerimizi içe aktar | |
| from prompt_templates import PROMPT_CATEGORIES | |
| from chatbot_backend import chatbot, ai_interface | |
| from api_integrations import ( | |
| api_manager, | |
| openai_handler, | |
| gemini_handler, | |
| openrouter_handler | |
| ) | |
| def main(): | |
| """ | |
| Ana Streamlit uygulaması. | |
| """ | |
| # Sayfa yapılandırması | |
| st.set_page_config( | |
| page_title="AI MEVZULARI - Prompt Mühendisi (Eray Coşkun Tarafından Aboneleri için geliştirilmiştir)", | |
| page_icon="🤖", | |
| layout="wide", | |
| initial_sidebar_state="expanded" | |
| ) | |
| # Session state başlatma | |
| if "api_keys" not in st.session_state: | |
| st.session_state.api_keys = { | |
| "openai": os.getenv("OPENAI_API_KEY", ""), | |
| "gemini": os.getenv("GEMINI_API_KEY", ""), | |
| "openrouter": os.getenv("OPENROUTER_API_KEY", "") | |
| } | |
| # Başlık ve açıklama | |
| st.title("AI MEVZULARI - Prompt Mühendisi (Eray Coşkun Tarafından Aboneleri için geliştirilmiştir)") | |
| st.markdown("Bu uygulama, AI modellerine verilecek detaylı promptlar oluşturmanıza yardımcı olur.") | |
| # Sidebar - API anahtarları | |
| with st.sidebar: | |
| st.header("API Anahtarları") | |
| st.info("API anahtarlarınızı girin. Bu anahtarlar oturum süresince saklanır ve sayfayı yenilediğinizde silinir.") | |
| # OpenAI API anahtarı | |
| openai_api_key = st.text_input( | |
| "OpenAI API Anahtarı", | |
| type="password", | |
| value=st.session_state.api_keys.get("openai", "") | |
| ) | |
| # Google Gemini API anahtarı | |
| gemini_api_key = st.text_input( | |
| "Google Gemini API Anahtarı", | |
| type="password", | |
| value=st.session_state.api_keys.get("gemini", "") | |
| ) | |
| # OpenRouter API anahtarı | |
| openrouter_api_key = st.text_input( | |
| "OpenRouter API Anahtarı", | |
| type="password", | |
| value=st.session_state.api_keys.get("openrouter", "") | |
| ) | |
| # API anahtarlarını kaydet | |
| if st.button("API Anahtarlarını Kaydet"): | |
| # Session state'e API anahtarlarını kaydet | |
| st.session_state.api_keys = { | |
| "openai": openai_api_key, | |
| "gemini": gemini_api_key, | |
| "openrouter": openrouter_api_key | |
| } | |
| # API anahtarlarını ayarla | |
| api_manager.set_api_key("openai", openai_api_key) | |
| api_manager.set_api_key("gemini", gemini_api_key) | |
| api_manager.set_api_key("openrouter", openrouter_api_key) | |
| # API işleyicilerine de anahtarları ayarla | |
| openai_handler.set_api_key(openai_api_key) | |
| gemini_handler.set_api_key(gemini_api_key) | |
| openrouter_handler.set_api_key(openrouter_api_key) | |
| # Chatbot'un AI prompt generator'ına da anahtarları ayarla | |
| chatbot.ai_generator.set_api_key("openai", openai_api_key) | |
| chatbot.ai_generator.set_api_key("gemini", gemini_api_key) | |
| chatbot.ai_generator.set_api_key("openrouter", openrouter_api_key) | |
| st.success("API anahtarları başarıyla kaydedildi!") | |
| # API anahtarlarının durumunu göster | |
| with st.expander("API Anahtarı Durumu", expanded=False): | |
| openai_status = "✅ Ayarlandı" if st.session_state.api_keys.get("openai") else "❌ Ayarlanmadı" | |
| gemini_status = "✅ Ayarlandı" if st.session_state.api_keys.get("gemini") else "❌ Ayarlanmadı" | |
| openrouter_status = "✅ Ayarlandı" if st.session_state.api_keys.get("openrouter") else "❌ Ayarlanmadı" | |
| st.write(f"OpenAI API: {openai_status}") | |
| st.write(f"Gemini API: {gemini_status}") | |
| st.write(f"OpenRouter API: {openrouter_status}") | |
| # AI modeli seçimi | |
| st.header("AI Modeli Seçimi") | |
| # API sağlayıcısı seçimi | |
| provider = st.selectbox( | |
| "API Sağlayıcısı", | |
| ["OpenAI", "Google Gemini", "OpenRouter"], | |
| index=0 | |
| ) | |
| # Seçilen sağlayıcıya göre model listesini al | |
| provider_key = provider.lower().replace(" ", "_") | |
| if provider_key == "google_gemini": | |
| provider_key = "gemini" | |
| # Modelleri al | |
| models = [] | |
| if provider_key == "openai": | |
| models = openai_handler.get_available_models() | |
| elif provider_key == "gemini": | |
| models = gemini_handler.get_available_models() | |
| elif provider_key == "openrouter": | |
| models = openrouter_handler.get_available_models() | |
| # Model seçimi | |
| selected_model = None | |
| if models: | |
| selected_model = st.selectbox("Model", models) | |
| # Ana içerik | |
| col1, col2 = st.columns([1, 1]) | |
| with col1: | |
| st.header("Prompt Oluştur") | |
| # Kullanıcı girdisi | |
| user_input = st.text_area( | |
| "Ne yapmak istediğinizi açıklayın:", | |
| height=150, | |
| placeholder="Örnek: Bir e-ticaret web sitesi yapmak istiyorum. Ürünleri listeleyebilmeli, sepete ekleyebilmeli ve ödeme alabilmeliyim." | |
| ) | |
| # AI destekli prompt oluşturma seçeneği | |
| if "use_ai_generation" not in st.session_state: | |
| st.session_state.use_ai_generation = True | |
| use_ai_generation = st.checkbox( | |
| "AI destekli prompt oluşturma kullan", | |
| value=st.session_state.use_ai_generation, | |
| key="use_ai_generation_checkbox" | |
| ) | |
| # Checkbox değiştiğinde session state'i güncelle | |
| st.session_state.use_ai_generation = use_ai_generation | |
| # API anahtarı kontrolü ve uyarı | |
| selected_provider_key = provider.lower().replace(" ", "_") | |
| if selected_provider_key == "google_gemini": | |
| selected_provider_key = "gemini" | |
| if use_ai_generation and not st.session_state.api_keys.get(selected_provider_key): | |
| st.warning(f"AI destekli prompt oluşturma için {provider} API anahtarı gereklidir. Lütfen API anahtarınızı girin ve 'API Anahtarlarını Kaydet' butonuna tıklayın.") | |
| # Prompt oluştur butonu | |
| if st.button("Prompt Oluştur"): | |
| if user_input: | |
| with st.spinner("Prompt oluşturuluyor..."): | |
| # Prompt oluştur | |
| provider_key = provider.lower().replace(" ", "_") | |
| if provider_key == "google_gemini": | |
| provider_key = "gemini" | |
| # API anahtarı kontrolü | |
| if use_ai_generation and not st.session_state.api_keys.get(provider_key): | |
| st.error(f"AI destekli prompt oluşturma için {provider} API anahtarı gereklidir. Lütfen API anahtarınızı girin ve 'API Anahtarlarını Kaydet' butonuna tıklayın.") | |
| else: | |
| # Debug bilgisi | |
| st.session_state.debug_info = { | |
| "use_ai_generation": use_ai_generation, | |
| "provider": provider_key, | |
| "model": selected_model, | |
| "api_key_set": bool(st.session_state.api_keys.get(provider_key)) | |
| } | |
| prompt, category, params = chatbot.process_input( | |
| user_input, | |
| use_ai_generation=use_ai_generation, | |
| provider=provider_key, | |
| model=selected_model | |
| ) | |
| # Sonuçları session state'e kaydet | |
| st.session_state.prompt = prompt | |
| st.session_state.category = category | |
| st.session_state.params = params | |
| # Sonuçları göster | |
| st.success("Prompt başarıyla oluşturuldu!") | |
| else: | |
| st.error("Lütfen ne yapmak istediğinizi açıklayın.") | |
| with col2: | |
| st.header("Oluşturulan Prompt") | |
| # Debug bilgisi (geliştirme aşamasında) | |
| if "debug_info" in st.session_state: | |
| with st.expander("Debug Bilgisi", expanded=False): | |
| st.write(st.session_state.debug_info) | |
| # Oluşturulan promptu göster | |
| if "prompt" in st.session_state: | |
| st.subheader(f"Kategori: {st.session_state.category}") | |
| # Parametreleri göster | |
| if st.session_state.params: | |
| with st.expander("Parametreler", expanded=False): | |
| for key, value in st.session_state.params.items(): | |
| st.write(f"**{key}:** {value}") | |
| # Promptu göster | |
| st.text_area( | |
| "Prompt:", | |
| value=st.session_state.prompt, | |
| height=400, | |
| disabled=True | |
| ) | |
| # Promptu kopyala butonu | |
| if st.button("Promptu Kopyala"): | |
| st.code(st.session_state.prompt) | |
| st.info("Yukarıdaki kodu seçip kopyalayabilirsiniz.") | |
| # AI ile Test Et bölümü | |
| st.subheader("AI ile Test Et") | |
| # Test için API sağlayıcısı seçimi | |
| test_provider = st.selectbox( | |
| "Test için API Sağlayıcısı", | |
| ["OpenAI", "Google Gemini", "OpenRouter"], | |
| index=0, | |
| key="test_provider" | |
| ) | |
| # Test için model seçimi | |
| test_provider_key = test_provider.lower().replace(" ", "_") | |
| if test_provider_key == "google_gemini": | |
| test_provider_key = "gemini" | |
| # Test için modelleri al | |
| test_models = [] | |
| if test_provider_key == "openai": | |
| test_models = openai_handler.get_available_models() | |
| elif test_provider_key == "gemini": | |
| test_models = gemini_handler.get_available_models() | |
| elif test_provider_key == "openrouter": | |
| test_models = openrouter_handler.get_available_models() | |
| # Test için model seçimi | |
| test_selected_model = None | |
| if test_models: | |
| test_selected_model = st.selectbox("Test için Model", test_models, key="test_model") | |
| # Test için API anahtarı giriş alanı | |
| st.markdown("### Test için API Anahtarı") | |
| st.info("Test için API anahtarını doğrudan buraya girebilirsiniz.") | |
| test_api_key = st.text_input( | |
| f"{test_provider} API Anahtarı (Test için)", | |
| type="password", | |
| key="test_api_key" | |
| ) | |
| # Kod şablonları oluşturma seçeneği | |
| generate_code_templates = st.checkbox("Kod şablonları ve dizin yapısı oluştur", value=True, key="generate_code_templates") | |
| # AI ile Test Et butonu | |
| if st.button("AI ile Test Et"): | |
| if "prompt" in st.session_state: | |
| if not test_api_key: | |
| st.error(f"Lütfen test için {test_provider} API anahtarını girin.") | |
| else: | |
| with st.spinner("AI yanıtı alınıyor..."): | |
| if generate_code_templates: | |
| # Kod şablonları ile yanıt al | |
| result = ai_interface.generate_response_with_code_templates( | |
| test_provider_key, | |
| st.session_state.prompt, | |
| test_selected_model, | |
| test_api_key | |
| ) | |
| # Yanıtı ve şablonları session state'e kaydet | |
| st.session_state.ai_response = result["response"] | |
| st.session_state.code_templates = result["templates"] | |
| else: | |
| # Sadece yanıt al | |
| response = ai_interface.generate_response( | |
| test_provider_key, | |
| st.session_state.prompt, | |
| test_selected_model, | |
| test_api_key | |
| ) | |
| # Yanıtı session state'e kaydet | |
| st.session_state.ai_response = response | |
| if "code_templates" in st.session_state: | |
| del st.session_state.code_templates | |
| # Yanıtı göster | |
| st.success("AI yanıtı başarıyla alındı!") | |
| else: | |
| st.error("Lütfen önce bir prompt oluşturun.") | |
| # AI yanıtını göster | |
| if "ai_response" in st.session_state: | |
| st.subheader("AI Yanıtı") | |
| st.text_area( | |
| "Yanıt:", | |
| value=st.session_state.ai_response, | |
| height=400, | |
| disabled=True | |
| ) | |
| # Kod şablonları ve dizin yapısı varsa göster | |
| if "code_templates" in st.session_state: | |
| templates = st.session_state.code_templates | |
| # Dizin yapısı | |
| if templates["directory_structure"]: | |
| with st.expander("📁 Dizin Yapısı", expanded=True): | |
| for structure in templates["directory_structure"]: | |
| st.code(structure, language="bash") | |
| # Kod şablonları | |
| if templates["code_templates"]: | |
| with st.expander("💻 Kod Şablonları", expanded=True): | |
| for template in templates["code_templates"]: | |
| st.subheader(f"{template['language'].capitalize()} Dosyası") | |
| st.code(template["code"], language=template["language"]) | |
| # Uygulama adımları | |
| if templates["implementation_steps"]: | |
| with st.expander("📝 Uygulama Adımları", expanded=True): | |
| for i, step in enumerate(templates["implementation_steps"]): | |
| if not step.startswith(f"{i+1}.") and not step.startswith("##"): | |
| st.markdown(f"**Adım {i+1}:** {step}") | |
| else: | |
| st.markdown(step) | |
| else: | |
| st.info("Henüz bir prompt oluşturulmadı. Sol taraftaki formu doldurup 'Prompt Oluştur' butonuna tıklayın.") | |
| # Kategori bilgileri | |
| st.header("Desteklenen Kategoriler") | |
| # Kategorileri göster | |
| categories_per_row = 3 | |
| categories = list(PROMPT_CATEGORIES.keys()) | |
| for i in range(0, len(categories), categories_per_row): | |
| cols = st.columns(categories_per_row) | |
| for j in range(categories_per_row): | |
| if i + j < len(categories): | |
| with cols[j]: | |
| category = categories[i + j] | |
| st.subheader(category) | |
| if isinstance(PROMPT_CATEGORIES[category], dict) and "description" in PROMPT_CATEGORIES[category]: | |
| st.write(PROMPT_CATEGORIES[category]["description"]) | |
| else: | |
| st.write("Bu kategori için açıklama bulunmuyor.") | |
| # Footer | |
| st.markdown("---") | |
| st.markdown("© 2025 AI Prompt Generator | Tüm hakları saklıdır.| created by Eray Coşkun") | |
| if __name__ == "__main__": | |
| main() | |
