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 Prompt Generator", | |
| page_icon="🤖", | |
| layout="wide", | |
| initial_sidebar_state="expanded" | |
| ) | |
| # Başlık ve açıklama | |
| st.title("AI Prompt Generator") | |
| 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=os.getenv("OPENAI_API_KEY", "") | |
| ) | |
| # Google Gemini API anahtarı | |
| gemini_api_key = st.text_input( | |
| "Google Gemini API Anahtarı", | |
| type="password", | |
| value=os.getenv("GEMINI_API_KEY", "") | |
| ) | |
| # OpenRouter API anahtarı | |
| openrouter_api_key = st.text_input( | |
| "OpenRouter API Anahtarı", | |
| type="password", | |
| value=os.getenv("OPENROUTER_API_KEY", "") | |
| ) | |
| # API anahtarlarını kaydet | |
| if st.button("API Anahtarlarını Kaydet"): | |
| # 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!") | |
| # 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 | |
| use_ai_generation = st.checkbox("AI destekli prompt oluşturma kullan", value=True) | |
| # 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" | |
| 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") | |
| # 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=500, | |
| disabled=True | |
| ) | |
| # Promptu kopyala butonu | |
| if st.button("Promptu Kopyala"): | |
| st.code(st.session_state.prompt) | |
| st.info("Yukarıdaki kodu seçip kopyalayabilirsiniz.") | |
| 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) | |
| st.write(PROMPT_CATEGORIES[category]["description"]) | |
| # Footer | |
| st.markdown("---") | |
| st.markdown("© 2025 AI Prompt Generator | Tüm hakları saklıdır.") | |
| if __name__ == "__main__": | |
| main() | |