File size: 7,185 Bytes
82e8868
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
"""
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()