aimevzulari commited on
Commit
0932e12
·
verified ·
1 Parent(s): fddc7c6

Delete streamlit_ui.py

Browse files
Files changed (1) hide show
  1. streamlit_ui.py +0 -347
streamlit_ui.py DELETED
@@ -1,347 +0,0 @@
1
- """
2
- Streamlit UI için modül.
3
- Bu modül, Streamlit kullanarak web arayüzünü oluşturur.
4
- """
5
-
6
- import streamlit as st
7
- import os
8
- from typing import Dict, Any, Optional
9
-
10
- # Kendi modüllerimizi içe aktar
11
- from prompt_templates import PROMPT_CATEGORIES
12
- from chatbot_backend import chatbot, ai_interface
13
- from api_integrations import (
14
- api_manager,
15
- openai_handler,
16
- gemini_handler,
17
- openrouter_handler
18
- )
19
-
20
- def main():
21
- """
22
- Ana Streamlit uygulaması.
23
- """
24
- # Sayfa yapılandırması
25
- st.set_page_config(
26
- page_title="AI Prompt Generator",
27
- page_icon="🤖",
28
- layout="wide",
29
- initial_sidebar_state="expanded"
30
- )
31
-
32
- # Session state başlatma
33
- if "api_keys" not in st.session_state:
34
- st.session_state.api_keys = {
35
- "openai": os.getenv("OPENAI_API_KEY", ""),
36
- "gemini": os.getenv("GEMINI_API_KEY", ""),
37
- "openrouter": os.getenv("OPENROUTER_API_KEY", "")
38
- }
39
-
40
- # Başlık ve açıklama
41
- st.title("AI Prompt Generator")
42
- st.markdown("Bu uygulama, AI modellerine verilecek detaylı promptlar oluşturmanıza yardımcı olur.")
43
-
44
- # Sidebar - API anahtarları
45
- with st.sidebar:
46
- st.header("API Anahtarları")
47
-
48
- st.info("API anahtarlarınızı girin. Bu anahtarlar oturum süresince saklanır ve sayfayı yenilediğinizde silinir.")
49
-
50
- # OpenAI API anahtarı
51
- openai_api_key = st.text_input(
52
- "OpenAI API Anahtarı",
53
- type="password",
54
- value=st.session_state.api_keys.get("openai", "")
55
- )
56
-
57
- # Google Gemini API anahtarı
58
- gemini_api_key = st.text_input(
59
- "Google Gemini API Anahtarı",
60
- type="password",
61
- value=st.session_state.api_keys.get("gemini", "")
62
- )
63
-
64
- # OpenRouter API anahtarı
65
- openrouter_api_key = st.text_input(
66
- "OpenRouter API Anahtarı",
67
- type="password",
68
- value=st.session_state.api_keys.get("openrouter", "")
69
- )
70
-
71
- # API anahtarlarını kaydet
72
- if st.button("API Anahtarlarını Kaydet"):
73
- # Session state'e API anahtarlarını kaydet
74
- st.session_state.api_keys = {
75
- "openai": openai_api_key,
76
- "gemini": gemini_api_key,
77
- "openrouter": openrouter_api_key
78
- }
79
-
80
- # API anahtarlarını ayarla
81
- api_manager.set_api_key("openai", openai_api_key)
82
- api_manager.set_api_key("gemini", gemini_api_key)
83
- api_manager.set_api_key("openrouter", openrouter_api_key)
84
-
85
- # API işleyicilerine de anahtarları ayarla
86
- openai_handler.set_api_key(openai_api_key)
87
- gemini_handler.set_api_key(gemini_api_key)
88
- openrouter_handler.set_api_key(openrouter_api_key)
89
-
90
- # Chatbot'un AI prompt generator'ına da anahtarları ayarla
91
- chatbot.ai_generator.set_api_key("openai", openai_api_key)
92
- chatbot.ai_generator.set_api_key("gemini", gemini_api_key)
93
- chatbot.ai_generator.set_api_key("openrouter", openrouter_api_key)
94
-
95
- st.success("API anahtarları başarıyla kaydedildi!")
96
-
97
- # API anahtarlarının durumunu göster
98
- with st.expander("API Anahtarı Durumu", expanded=False):
99
- openai_status = "✅ Ayarlandı" if st.session_state.api_keys.get("openai") else "❌ Ayarlanmadı"
100
- gemini_status = "✅ Ayarlandı" if st.session_state.api_keys.get("gemini") else "❌ Ayarlanmadı"
101
- openrouter_status = "✅ Ayarlandı" if st.session_state.api_keys.get("openrouter") else "❌ Ayarlanmadı"
102
-
103
- st.write(f"OpenAI API: {openai_status}")
104
- st.write(f"Gemini API: {gemini_status}")
105
- st.write(f"OpenRouter API: {openrouter_status}")
106
-
107
- # AI modeli seçimi
108
- st.header("AI Modeli Seçimi")
109
-
110
- # API sağlayıcısı seçimi
111
- provider = st.selectbox(
112
- "API Sağlayıcısı",
113
- ["OpenAI", "Google Gemini", "OpenRouter"],
114
- index=0
115
- )
116
-
117
- # Seçilen sağlayıcıya göre model listesini al
118
- provider_key = provider.lower().replace(" ", "_")
119
- if provider_key == "google_gemini":
120
- provider_key = "gemini"
121
-
122
- # Modelleri al
123
- models = []
124
- if provider_key == "openai":
125
- models = openai_handler.get_available_models()
126
- elif provider_key == "gemini":
127
- models = gemini_handler.get_available_models()
128
- elif provider_key == "openrouter":
129
- models = openrouter_handler.get_available_models()
130
-
131
- # Model seçimi
132
- selected_model = None
133
- if models:
134
- selected_model = st.selectbox("Model", models)
135
-
136
- # Ana içerik
137
- col1, col2 = st.columns([1, 1])
138
-
139
- with col1:
140
- st.header("Prompt Oluştur")
141
-
142
- # Kullanıcı girdisi
143
- user_input = st.text_area(
144
- "Ne yapmak istediğinizi açıklayın:",
145
- height=150,
146
- placeholder="Örnek: Bir e-ticaret web sitesi yapmak istiyorum. Ürünleri listeleyebilmeli, sepete ekleyebilmeli ve ödeme alabilmeliyim."
147
- )
148
-
149
- # AI destekli prompt oluşturma seçeneği
150
- use_ai_generation = st.checkbox("AI destekli prompt oluşturma kullan", value=True)
151
-
152
- # Prompt oluştur butonu
153
- if st.button("Prompt Oluştur"):
154
- if user_input:
155
- with st.spinner("Prompt oluşturuluyor..."):
156
- # Prompt oluştur
157
- provider_key = provider.lower().replace(" ", "_")
158
- if provider_key == "google_gemini":
159
- provider_key = "gemini"
160
-
161
- prompt, category, params = chatbot.process_input(
162
- user_input,
163
- use_ai_generation=use_ai_generation,
164
- provider=provider_key,
165
- model=selected_model
166
- )
167
-
168
- # Sonuçları session state'e kaydet
169
- st.session_state.prompt = prompt
170
- st.session_state.category = category
171
- st.session_state.params = params
172
-
173
- # Sonuçları göster
174
- st.success("Prompt başarıyla oluşturuldu!")
175
- else:
176
- st.error("Lütfen ne yapmak istediğinizi açıklayın.")
177
-
178
- with col2:
179
- st.header("Oluşturulan Prompt")
180
-
181
- # Oluşturulan promptu göster
182
- if "prompt" in st.session_state:
183
- st.subheader(f"Kategori: {st.session_state.category}")
184
-
185
- # Parametreleri göster
186
- if st.session_state.params:
187
- with st.expander("Parametreler", expanded=False):
188
- for key, value in st.session_state.params.items():
189
- st.write(f"**{key}:** {value}")
190
-
191
- # Promptu göster
192
- st.text_area(
193
- "Prompt:",
194
- value=st.session_state.prompt,
195
- height=400,
196
- disabled=True
197
- )
198
-
199
- # Promptu kopyala butonu
200
- if st.button("Promptu Kopyala"):
201
- st.code(st.session_state.prompt)
202
- st.info("Yukarıdaki kodu seçip kopyalayabilirsiniz.")
203
-
204
- # AI ile Test Et bölümü
205
- st.subheader("AI ile Test Et")
206
-
207
- # Test için API sağlayıcısı seçimi
208
- test_provider = st.selectbox(
209
- "Test için API Sağlayıcısı",
210
- ["OpenAI", "Google Gemini", "OpenRouter"],
211
- index=0,
212
- key="test_provider"
213
- )
214
-
215
- # Test için model seçimi
216
- test_provider_key = test_provider.lower().replace(" ", "_")
217
- if test_provider_key == "google_gemini":
218
- test_provider_key = "gemini"
219
-
220
- # Test için modelleri al
221
- test_models = []
222
- if test_provider_key == "openai":
223
- test_models = openai_handler.get_available_models()
224
- elif test_provider_key == "gemini":
225
- test_models = gemini_handler.get_available_models()
226
- elif test_provider_key == "openrouter":
227
- test_models = openrouter_handler.get_available_models()
228
-
229
- # Test için model seçimi
230
- test_selected_model = None
231
- if test_models:
232
- test_selected_model = st.selectbox("Test için Model", test_models, key="test_model")
233
-
234
- # Test için API anahtarı giriş alanı
235
- st.markdown("### Test için API Anahtarı")
236
- st.info("Test için API anahtarını doğrudan buraya girebilirsiniz.")
237
-
238
- test_api_key = st.text_input(
239
- f"{test_provider} API Anahtarı (Test için)",
240
- type="password",
241
- key="test_api_key"
242
- )
243
-
244
- # Kod şablonları oluşturma seçeneği
245
- generate_code_templates = st.checkbox("Kod şablonları ve dizin yapısı oluştur", value=True, key="generate_code_templates")
246
-
247
- # AI ile Test Et butonu
248
- if st.button("AI ile Test Et"):
249
- if "prompt" in st.session_state:
250
- if not test_api_key:
251
- st.error(f"Lütfen test için {test_provider} API anahtarını girin.")
252
- else:
253
- with st.spinner("AI yanıtı alınıyor..."):
254
- if generate_code_templates:
255
- # Kod şablonları ile yanıt al
256
- result = ai_interface.generate_response_with_code_templates(
257
- test_provider_key,
258
- st.session_state.prompt,
259
- test_selected_model,
260
- test_api_key
261
- )
262
-
263
- # Yanıtı ve şablonları session state'e kaydet
264
- st.session_state.ai_response = result["response"]
265
- st.session_state.code_templates = result["templates"]
266
- else:
267
- # Sadece yanıt al
268
- response = ai_interface.generate_response(
269
- test_provider_key,
270
- st.session_state.prompt,
271
- test_selected_model,
272
- test_api_key
273
- )
274
-
275
- # Yanıtı session state'e kaydet
276
- st.session_state.ai_response = response
277
- if "code_templates" in st.session_state:
278
- del st.session_state.code_templates
279
-
280
- # Yanıtı göster
281
- st.success("AI yanıtı başarıyla alındı!")
282
- else:
283
- st.error("Lütfen önce bir prompt oluşturun.")
284
-
285
- # AI yanıtını göster
286
- if "ai_response" in st.session_state:
287
- st.subheader("AI Yanıtı")
288
- st.text_area(
289
- "Yanıt:",
290
- value=st.session_state.ai_response,
291
- height=400,
292
- disabled=True
293
- )
294
-
295
- # Kod şablonları ve dizin yapısı varsa göster
296
- if "code_templates" in st.session_state:
297
- templates = st.session_state.code_templates
298
-
299
- # Dizin yapısı
300
- if templates["directory_structure"]:
301
- with st.expander("📁 Dizin Yapısı", expanded=True):
302
- for structure in templates["directory_structure"]:
303
- st.code(structure, language="bash")
304
-
305
- # Kod şablonları
306
- if templates["code_templates"]:
307
- with st.expander("💻 Kod Şablonları", expanded=True):
308
- for template in templates["code_templates"]:
309
- st.subheader(f"{template['language'].capitalize()} Dosyası")
310
- st.code(template["code"], language=template["language"])
311
-
312
- # Uygulama adımları
313
- if templates["implementation_steps"]:
314
- with st.expander("📝 Uygulama Adımları", expanded=True):
315
- for i, step in enumerate(templates["implementation_steps"]):
316
- if not step.startswith(f"{i+1}.") and not step.startswith("##"):
317
- st.markdown(f"**Adım {i+1}:** {step}")
318
- else:
319
- st.markdown(step)
320
- else:
321
- st.info("Henüz bir prompt oluşturulmadı. Sol taraftaki formu doldurup 'Prompt Oluştur' butonuna tıklayın.")
322
-
323
- # Kategori bilgileri
324
- st.header("Desteklenen Kategoriler")
325
-
326
- # Kategorileri göster
327
- categories_per_row = 3
328
- categories = list(PROMPT_CATEGORIES.keys())
329
-
330
- for i in range(0, len(categories), categories_per_row):
331
- cols = st.columns(categories_per_row)
332
- for j in range(categories_per_row):
333
- if i + j < len(categories):
334
- with cols[j]:
335
- category = categories[i + j]
336
- st.subheader(category)
337
- if isinstance(PROMPT_CATEGORIES[category], dict) and "description" in PROMPT_CATEGORIES[category]:
338
- st.write(PROMPT_CATEGORIES[category]["description"])
339
- else:
340
- st.write("Bu kategori için açıklama bulunmuyor.")
341
-
342
- # Footer
343
- st.markdown("---")
344
- st.markdown("© 2025 AI Prompt Generator | Tüm hakları saklıdır.")
345
-
346
- if __name__ == "__main__":
347
- main()