therayz1 commited on
Commit
5b7d6e5
·
verified ·
1 Parent(s): 7819e29

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +526 -0
app.py ADDED
@@ -0,0 +1,526 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import time
4
+ import os
5
+ from datetime import datetime
6
+ from llm_utils import LLM_PROVIDERS, get_llm_models, validate_api_key, call_llm, parse_llm_output, create_zip_from_files
7
+ from project_types import PROJECT_TYPES
8
+ from advanced_prompts import (
9
+ get_advanced_context_prompt,
10
+ get_advanced_commands_prompt,
11
+ get_advanced_prompts_prompt,
12
+ calculate_project_complexity,
13
+ get_industry_specific_requirements
14
+ )
15
+
16
+ # Global state
17
+ generated_files = {'context': {}, 'commands': {}, 'prompts': {}}
18
+ stats = {'context': {'tokens': 0, 'time': 0}, 'commands': {'tokens': 0, 'time': 0}, 'prompts': {'tokens': 0, 'time': 0}}
19
+ project_analysis = {}
20
+
21
+ # Sektörler
22
+ INDUSTRIES = [
23
+ "Teknoloji/Yazılım", "Finans/Fintech", "Sağlık/Healthcare",
24
+ "E-ticaret", "Eğitim/EdTech", "Oyun/Gaming", "Sosyal Medya",
25
+ "IoT/Akıllı Cihazlar", "Blockchain/Web3", "AI/ML Servisleri",
26
+ "SaaS B2B", "SaaS B2C", "Marketplace", "Diğer"
27
+ ]
28
+
29
+ # Proje özellikleri
30
+ PROJECT_FEATURES = [
31
+ "Kullanıcı Yönetimi", "Ödeme İşlemleri", "Gerçek Zamanlı Özellikler",
32
+ "AI/ML Entegrasyonu", "Çoklu Platform", "3. Parti Entegrasyonlar",
33
+ "Offline Çalışma", "Çoklu Dil Desteği", "Bildirim Sistemi",
34
+ "Analytics/Raporlama", "Sosyal Özellikler", "Güvenlik/Compliance"
35
+ ]
36
+
37
+ def analyze_project(project_type, project_idea, industry, features):
38
+ """Proje analizi yapar ve öneriler üretir"""
39
+ analysis = {
40
+ "complexity": calculate_project_complexity(project_type, project_idea, features),
41
+ "industry_requirements": get_industry_specific_requirements(industry),
42
+ "estimated_files": {},
43
+ "tech_recommendations": [],
44
+ "architecture_suggestion": ""
45
+ }
46
+
47
+ # Teknoloji önerileri
48
+ if "AI/ML" in project_type:
49
+ analysis["tech_recommendations"] = ["Python", "TensorFlow/PyTorch", "MLflow", "Docker", "Kubernetes"]
50
+ analysis["architecture_suggestion"] = "Microservices with ML Pipeline"
51
+ elif "Web" in project_type:
52
+ analysis["tech_recommendations"] = ["React/Next.js", "Node.js/Python", "PostgreSQL", "Redis", "Docker"]
53
+ analysis["architecture_suggestion"] = "Modern Jamstack Architecture"
54
+ elif "Mobil" in project_type:
55
+ analysis["tech_recommendations"] = ["React Native/Flutter", "Firebase", "GraphQL", "Redux/MobX"]
56
+ analysis["architecture_suggestion"] = "Clean Architecture with BLoC/MVVM"
57
+
58
+ return analysis
59
+
60
+ def generate_section_advanced(provider, model, api_key, project_type, project_idea,
61
+ section, industry, features, tech_details, progress=gr.Progress()):
62
+ """Gelişmiş section oluşturma"""
63
+ try:
64
+ start_time = time.time()
65
+
66
+ # Proje analizi
67
+ progress(0.05, desc="Proje analiz ediliyor...")
68
+ analysis = analyze_project(project_type, project_idea, industry, features)
69
+ global project_analysis
70
+ project_analysis = analysis
71
+
72
+ # Progress
73
+ progress(0.1, desc=f"{section.capitalize()} için akıllı prompt hazırlanıyor...")
74
+
75
+ # Section'a göre advanced prompt seç
76
+ if section == 'context':
77
+ prompt = get_advanced_context_prompt(project_type, project_idea, tech_details)
78
+ elif section == 'commands':
79
+ context_summary = f"Proje {len(generated_files['context'])} context dosyası içeriyor"
80
+ prompt = get_advanced_commands_prompt(project_type, project_idea, context_summary)
81
+ elif section == 'prompts':
82
+ prompt = get_advanced_prompts_prompt(project_type, project_idea, tech_details)
83
+
84
+ # Sektör gereksinimlerini ekle
85
+ if industry != "Diğer":
86
+ prompt += f"\n\nSEKTÖR GEREKSİNİMLERİ ({industry}):\n"
87
+ prompt += "\n".join(f"- {req}" for req in analysis["industry_requirements"])
88
+
89
+ # Token tahmini
90
+ prompt_tokens = len(prompt.split()) * 1.3
91
+
92
+ progress(0.3, desc="AI ile iletişim kuruluyor...")
93
+
94
+ # LLM çağrısı
95
+ llm_response = call_llm(provider, model, api_key, prompt)
96
+
97
+ if not llm_response or "hata" in llm_response.lower():
98
+ return f"<p style='color:red;'>❌ Hata: {llm_response}</p>", None, None
99
+
100
+ progress(0.6, desc="Yanıt işleniyor ve optimize ediliyor...")
101
+
102
+ # Response analizi
103
+ response_tokens = len(llm_response.split()) * 1.3
104
+ total_tokens = prompt_tokens + response_tokens
105
+
106
+ # Dosyaları parse et
107
+ parsed_files = parse_llm_output(llm_response)
108
+
109
+ if not parsed_files:
110
+ return f"<p style='color:red;'>❌ Dosyalar ayrıştırılamadı.</p>", None, None
111
+
112
+ # Kaydet
113
+ generated_files[section] = parsed_files
114
+
115
+ # İstatistikleri güncelle
116
+ elapsed_time = time.time() - start_time
117
+ stats[section] = {'tokens': int(total_tokens), 'time': round(elapsed_time, 2)}
118
+
119
+ progress(0.9, desc="Kalite kontrolü yapılıyor...")
120
+
121
+ # Dosya listesi ve kalite skoru
122
+ file_count = len(parsed_files)
123
+ quality_score = min(100, 60 + (file_count * 4)) # Basit kalite skoru
124
+
125
+ # Başarı mesajı
126
+ file_list_html = "<div style='max-height: 200px; overflow-y: auto;'>"
127
+ for i, (file, content) in enumerate(parsed_files.items()):
128
+ size_kb = len(content.encode('utf-8')) / 1024
129
+ file_list_html += f"""
130
+ <div style='padding: 5px; border-bottom: 1px solid #e5e7eb;'>
131
+ <span style='color: #10b981;'>✅</span>
132
+ <strong>{file}</strong>
133
+ <span style='color: #6b7280; font-size: 0.9em;'>({size_kb:.1f} KB)</span>
134
+ </div>
135
+ """
136
+ file_list_html += "</div>"
137
+
138
+ success_msg = f"""
139
+ <div style='background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 20px; border-radius: 12px; color: white;'>
140
+ <h3 style='margin-top: 0;'>✨ {section.capitalize()} Başarıyla Oluşturuldu!</h3>
141
+ <div style='display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin: 15px 0;'>
142
+ <div style='background: rgba(255,255,255,0.2); padding: 10px; border-radius: 8px;'>
143
+ <div style='font-size: 24px; font-weight: bold;'>{file_count}</div>
144
+ <div style='font-size: 12px; opacity: 0.9;'>Dosya Oluşturuldu</div>
145
+ </div>
146
+ <div style='background: rgba(255,255,255,0.2); padding: 10px; border-radius: 8px;'>
147
+ <div style='font-size: 24px; font-weight: bold;'>~{int(total_tokens)}</div>
148
+ <div style='font-size: 12px; opacity: 0.9;'>Token Kullanıldı</div>
149
+ </div>
150
+ <div style='background: rgba(255,255,255,0.2); padding: 10px; border-radius: 8px;'>
151
+ <div style='font-size: 24px; font-weight: bold;'>{elapsed_time:.1f}s</div>
152
+ <div style='font-size: 12px; opacity: 0.9;'>İşlem Süresi</div>
153
+ </div>
154
+ </div>
155
+ <div style='margin-top: 15px;'>
156
+ <div style='font-weight: bold; margin-bottom: 10px;'>📁 Oluşturulan Dosyalar:</div>
157
+ {file_list_html}
158
+ </div>
159
+ <div style='margin-top: 15px; padding: 10px; background: rgba(255,255,255,0.1); border-radius: 8px;'>
160
+ <span style='font-weight: bold;'>Kalite Skoru:</span>
161
+ <span style='font-size: 20px;'>{quality_score}/100</span>
162
+ </div>
163
+ </div>
164
+ """
165
+
166
+ # Analiz raporu
167
+ analysis_report = f"""
168
+ <div style='margin-top: 20px; padding: 15px; background: #f3f4f6; border-radius: 8px;'>
169
+ <h4 style='margin-top: 0;'>📊 Proje Analizi</h4>
170
+ <ul style='margin: 10px 0;'>
171
+ <li><strong>Karmaşıklık:</strong> {analysis['complexity']['context'] + analysis['complexity']['commands'] + analysis['complexity']['prompts']} puan</li>
172
+ <li><strong>Sektör:</strong> {industry}</li>
173
+ <li><strong>Önerilen Teknolojiler:</strong> {', '.join(analysis['tech_recommendations'][:3])}</li>
174
+ <li><strong>Mimari:</strong> {analysis['architecture_suggestion']}</li>
175
+ </ul>
176
+ </div>
177
+ """
178
+
179
+ return success_msg + analysis_report, None, analysis
180
+
181
+ except Exception as e:
182
+ import traceback
183
+ error_detail = traceback.format_exc()
184
+ return f"<p style='color:red;'>❌ Hata: {str(e)}</p><pre>{error_detail}</pre>", None, None
185
+
186
+ def download_all_professional():
187
+ """Profesyonel ZIP paketi oluşturur"""
188
+ all_files = {}
189
+
190
+ # Dosyaları topla
191
+ for section in ['context', 'commands', 'prompts']:
192
+ if generated_files[section]:
193
+ all_files.update(generated_files[section])
194
+
195
+ if not all_files:
196
+ return None, "<p style='color:red;'>❌ İndirilecek dosya yok.</p>"
197
+
198
+ # README.md oluştur
199
+ readme_content = f"""# {project_analysis.get('project_name', 'Project')} - Context Engineering
200
+
201
+ ## 📋 Proje Özeti
202
+ - **Tür:** {project_analysis.get('project_type', 'N/A')}
203
+ - **Sektör:** {project_analysis.get('industry', 'N/A')}
204
+ - **Karmaşıklık:** {project_analysis.get('complexity', {}).get('context', 0) + project_analysis.get('complexity', {}).get('commands', 0) + project_analysis.get('complexity', {}).get('prompts', 0)} puan
205
+
206
+ ## 📁 Dosya Yapısı
207
+ - `context/` - Proje bağlamı ve dokümantasyon ({len(generated_files['context'])} dosya)
208
+ - `commands/` - Otomasyon ve yönetim komutları ({len(generated_files['commands'])} dosya)
209
+ - `prompts/` - AI asistan prompt şablonları ({len(generated_files['prompts'])} dosya)
210
+
211
+ ## 🚀 Başlangıç
212
+ 1. Context dosyalarını okuyarak projeyi anlayın
213
+ 2. Commands klasöründeki setup komutlarını çalıştırın
214
+ 3. Prompts şablonlarını AI asistanınızla kullanın
215
+
216
+ ## 📊 İstatistikler
217
+ - Toplam Dosya: {len(all_files)}
218
+ - Toplam Token: ~{sum(s['tokens'] for s in stats.values())}
219
+ - Oluşturma Süresi: {sum(s['time'] for s in stats.values()):.1f} saniye
220
+
221
+ ---
222
+ Generated by Context Engineer v2.0
223
+ """
224
+
225
+ all_files['README.md'] = readme_content
226
+
227
+ # Manifest dosyası
228
+ manifest = {
229
+ "version": "2.0",
230
+ "generated_at": datetime.now().isoformat(),
231
+ "statistics": stats,
232
+ "project_analysis": project_analysis,
233
+ "file_count": {
234
+ "context": len(generated_files['context']),
235
+ "commands": len(generated_files['commands']),
236
+ "prompts": len(generated_files['prompts'])
237
+ }
238
+ }
239
+ all_files['manifest.json'] = json.dumps(manifest, indent=2)
240
+
241
+ # ZIP oluştur
242
+ zip_data = create_zip_from_files(all_files)
243
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
244
+ zip_file_path = f"./context_engineering_pro_{timestamp}.zip"
245
+
246
+ with open(zip_file_path, "wb") as f:
247
+ f.write(zip_data)
248
+
249
+ # Özet rapor
250
+ total_size_kb = sum(len(content.encode('utf-8')) for content in all_files.values()) / 1024
251
+
252
+ summary = f"""
253
+ <div style='background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 30px; border-radius: 16px; color: white;'>
254
+ <h2 style='margin-top: 0;'>🎉 Proje Paketi Hazır!</h2>
255
+
256
+ <div style='display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin: 20px 0;'>
257
+ <div style='background: rgba(255,255,255,0.2); padding: 20px; border-radius: 12px;'>
258
+ <h3 style='margin-top: 0;'>📊 Genel İstatistikler</h3>
259
+ <ul style='list-style: none; padding: 0;'>
260
+ <li>📁 <strong>Toplam Dosya:</strong> {len(all_files)}</li>
261
+ <li>💾 <strong>Paket Boyutu:</strong> {total_size_kb:.1f} KB</li>
262
+ <li>🎯 <strong>Token Kullanımı:</strong> ~{sum(s['tokens'] for s in stats.values())}</li>
263
+ <li>⏱️ <strong>Toplam Süre:</strong> {sum(s['time'] for s in stats.values()):.1f}s</li>
264
+ </ul>
265
+ </div>
266
+
267
+ <div style='background: rgba(255,255,255,0.2); padding: 20px; border-radius: 12px;'>
268
+ <h3 style='margin-top: 0;'>📂 Klasör Detayları</h3>
269
+ <ul style='list-style: none; padding: 0;'>
270
+ <li>📘 <strong>Context:</strong> {len(generated_files['context'])} dosya</li>
271
+ <li>⚡ <strong>Commands:</strong> {len(generated_files['commands'])} dosya</li>
272
+ <li>💡 <strong>Prompts:</strong> {len(generated_files['prompts'])} dosya</li>
273
+ <li>📄 <strong>Ekstra:</strong> README.md, manifest.json</li>
274
+ </ul>
275
+ </div>
276
+ </div>
277
+
278
+ <div style='background: rgba(255,255,255,0.1); padding: 15px; border-radius: 8px; margin-top: 20px;'>
279
+ <p style='margin: 0; text-align: center; font-size: 18px;'>
280
+ ✨ Profesyonel context engineering paketiniz başarıyla oluşturuldu!
281
+ </p>
282
+ </div>
283
+ </div>
284
+ """
285
+
286
+ return gr.File(value=zip_file_path, visible=True), summary
287
+
288
+ # Ana arayüz
289
+ with gr.Blocks(theme=gr.themes.Soft(), css="""
290
+ .gradio-container {
291
+ font-family: 'Inter', sans-serif;
292
+ }
293
+ .gr-button-primary {
294
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
295
+ border: none;
296
+ }
297
+ .gr-button-secondary {
298
+ background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
299
+ border: none;
300
+ }
301
+ """) as demo:
302
+
303
+ gr.Markdown("""
304
+ # 🚀 Context Engineer Pro v2.0
305
+ ### Enterprise-Grade AI-Powered Project Structure Generator
306
+
307
+ Projeleriniz için **akıllı**, **dinamik** ve **sektöre özgü** context engineering yapıları oluşturun.
308
+ """)
309
+
310
+ with gr.Tab("🎯 Proje Bilgileri"):
311
+ with gr.Row():
312
+ with gr.Column(scale=1):
313
+ gr.Markdown("### 🏢 Proje Detayları")
314
+
315
+ project_type = gr.Dropdown(
316
+ choices=PROJECT_TYPES,
317
+ label="Proje Türü",
318
+ value=PROJECT_TYPES[0]
319
+ )
320
+
321
+ industry = gr.Dropdown(
322
+ choices=INDUSTRIES,
323
+ label="Sektör",
324
+ value="Teknoloji/Yazılım"
325
+ )
326
+
327
+ features = gr.CheckboxGroup(
328
+ choices=PROJECT_FEATURES,
329
+ label="Proje Özellikleri",
330
+ value=["Kullanıcı Yönetimi"]
331
+ )
332
+
333
+ with gr.Column(scale=2):
334
+ gr.Markdown("### 📝 Proje Açıklaması")
335
+
336
+ project_idea_input = gr.Textbox(
337
+ label="Proje Fikri",
338
+ lines=6,
339
+ value="Detaylı proje açıklamanızı buraya yazın..."
340
+ )
341
+
342
+ tech_details_input = gr.Textbox(
343
+ label="Teknik Detaylar (Opsiyonel)",
344
+ lines=4,
345
+ value="Kullanmayı düşündüğünüz teknolojiler, özel gereksinimler..."
346
+ )
347
+
348
+ with gr.Tab("🔧 LLM Konfigürasyonu"):
349
+ with gr.Row():
350
+ with gr.Column():
351
+ llm_provider = gr.Dropdown(
352
+ choices=list(LLM_PROVIDERS.keys()),
353
+ label="AI Sağlayıcı",
354
+ value="Gemini"
355
+ )
356
+
357
+ llm_model = gr.Dropdown(
358
+ choices=[],
359
+ label="Model",
360
+ interactive=False
361
+ )
362
+
363
+ with gr.Column():
364
+ api_key_input = gr.Textbox(
365
+ label="API Anahtarı",
366
+ type="password"
367
+ )
368
+
369
+ validate_button = gr.Button("🔐 API Doğrula", variant="secondary")
370
+ validation_status = gr.Markdown()
371
+
372
+ with gr.Tab("🏗️ Yapı Oluşturma"):
373
+ gr.Markdown("""
374
+ ### 🎨 Akıllı Dosya Üretimi
375
+ Her bölüm, projenizin özelliklerine göre **dinamik olarak** oluşturulur.
376
+ """)
377
+
378
+ with gr.Row():
379
+ context_btn = gr.Button("📘 Context Oluştur", variant="primary", size="lg")
380
+ commands_btn = gr.Button("⚡ Commands Oluştur", variant="primary", size="lg")
381
+ prompts_btn = gr.Button("💡 Prompts Oluştur", variant="primary", size="lg")
382
+
383
+ with gr.Row():
384
+ generate_all_btn = gr.Button("🎯 Hepsini Oluştur (Sırayla)", variant="secondary")
385
+ analyze_btn = gr.Button("🔍 Proje Analizi", variant="secondary")
386
+
387
+ output_display = gr.Markdown()
388
+ analysis_display = gr.Markdown()
389
+
390
+ with gr.Tab("📦 İndirme & İstatistikler"):
391
+ with gr.Row():
392
+ download_btn = gr.Button("📥 Profesyonel Paket İndir", variant="primary", size="lg")
393
+ clear_btn = gr.Button("🗑️ Temizle", variant="secondary")
394
+
395
+ download_file = gr.File(label="İndirilebilir Paket", visible=False)
396
+ stats_display = gr.Markdown()
397
+
398
+ # Event handlers
399
+ def update_models(provider):
400
+ if provider in LLM_PROVIDERS:
401
+ return gr.Dropdown(
402
+ choices=LLM_PROVIDERS[provider].get("models", []),
403
+ interactive=True
404
+ )
405
+ return gr.Dropdown(choices=[], interactive=False)
406
+
407
+ def validate_api(provider, api_key):
408
+ if not provider or not api_key:
409
+ return gr.Markdown("<p style='color:orange;'>⚠️ Sağlayıcı ve API anahtarı gerekli.</p>"), gr.Dropdown()
410
+
411
+ is_valid, message = validate_api_key(provider, api_key)
412
+ if is_valid:
413
+ models = get_llm_models(provider, api_key)
414
+ return (
415
+ gr.Markdown(f"<p style='color:green;'>✅ {message}</p>"),
416
+ gr.Dropdown(choices=models, value=models[0] if models else None, interactive=True)
417
+ )
418
+ return (
419
+ gr.Markdown(f"<p style='color:red;'>❌ {message}</p>"),
420
+ gr.Dropdown(choices=[], interactive=False)
421
+ )
422
+
423
+ def analyze_project_details(project_type, project_idea, industry, features):
424
+ analysis = analyze_project(project_type, project_idea, industry, features)
425
+
426
+ report = f"""
427
+ <div style='background: #f9fafb; padding: 20px; border-radius: 12px; border: 1px solid #e5e7eb;'>
428
+ <h3>🔍 Proje Analiz Raporu</h3>
429
+
430
+ <div style='display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px;'>
431
+ <div>
432
+ <h4>📊 Karmaşıklık Analizi</h4>
433
+ <ul>
434
+ <li>Context dosyaları: ~{analysis['complexity']['context']} adet</li>
435
+ <li>Command dosyaları: ~{analysis['complexity']['commands']} adet</li>
436
+ <li>Prompt şablonları: ~{analysis['complexity']['prompts']} adet</li>
437
+ </ul>
438
+ </div>
439
+
440
+ <div>
441
+ <h4>🛠️ Teknoloji Önerileri</h4>
442
+ <ul>
443
+ {"".join(f"<li>{tech}</li>" for tech in analysis['tech_recommendations'][:5])}
444
+ </ul>
445
+ </div>
446
+ </div>
447
+
448
+ <div style='margin-top: 20px;'>
449
+ <h4>🏗️ Önerilen Mimari</h4>
450
+ <p>{analysis['architecture_suggestion']}</p>
451
+ </div>
452
+
453
+ {f'''
454
+ <div style='margin-top: 20px;'>
455
+ <h4>🏢 Sektör Gereksinimleri ({industry})</h4>
456
+ <ul>
457
+ {"".join(f"<li>{req}</li>" for req in analysis['industry_requirements'])}
458
+ </ul>
459
+ </div>
460
+ ''' if analysis['industry_requirements'] else ''}
461
+ </div>
462
+ """
463
+ return report
464
+
465
+ def generate_all_sequential(provider, model, api_key, project_type, project_idea,
466
+ industry, features, tech_details):
467
+ results = []
468
+ for section in ['context', 'commands', 'prompts']:
469
+ result, _, _ = generate_section_advanced(
470
+ provider, model, api_key, project_type, project_idea,
471
+ section, industry, features, tech_details
472
+ )
473
+ results.append(result)
474
+ time.sleep(2) # Rate limiting
475
+
476
+ return "<br><br>".join(results)
477
+
478
+ def clear_all():
479
+ global generated_files, stats, project_analysis
480
+ generated_files = {'context': {}, 'commands': {}, 'prompts': {}}
481
+ stats = {'context': {'tokens': 0, 'time': 0}, 'commands': {'tokens': 0, 'time': 0}, 'prompts': {'tokens': 0, 'time': 0}}
482
+ project_analysis = {}
483
+ return gr.Markdown("✅ Tüm veriler temizlendi."), gr.File(visible=False), gr.Markdown("")
484
+
485
+ # Wire up events
486
+ llm_provider.change(fn=update_models, inputs=llm_provider, outputs=llm_model)
487
+ validate_button.click(fn=validate_api, inputs=[llm_provider, api_key_input], outputs=[validation_status, llm_model])
488
+
489
+ # Analyze button
490
+ analyze_btn.click(
491
+ fn=analyze_project_details,
492
+ inputs=[project_type, project_idea_input, industry, features],
493
+ outputs=analysis_display
494
+ )
495
+
496
+ # Section buttons
497
+ context_btn.click(
498
+ fn=lambda p, m, a, pt, pi, i, f, t: generate_section_advanced(p, m, a, pt, pi, 'context', i, f, t),
499
+ inputs=[llm_provider, llm_model, api_key_input, project_type, project_idea_input, industry, features, tech_details_input],
500
+ outputs=[output_display, download_file, analysis_display]
501
+ )
502
+
503
+ commands_btn.click(
504
+ fn=lambda p, m, a, pt, pi, i, f, t: generate_section_advanced(p, m, a, pt, pi, 'commands', i, f, t),
505
+ inputs=[llm_provider, llm_model, api_key_input, project_type, project_idea_input, industry, features, tech_details_input],
506
+ outputs=[output_display, download_file, analysis_display]
507
+ )
508
+
509
+ prompts_btn.click(
510
+ fn=lambda p, m, a, pt, pi, i, f, t: generate_section_advanced(p, m, a, pt, pi, 'prompts', i, f, t),
511
+ inputs=[llm_provider, llm_model, api_key_input, project_type, project_idea_input, industry, features, tech_details_input],
512
+ outputs=[output_display, download_file, analysis_display]
513
+ )
514
+
515
+ generate_all_btn.click(
516
+ fn=generate_all_sequential,
517
+ inputs=[llm_provider, llm_model, api_key_input, project_type, project_idea_input, industry, features, tech_details_input],
518
+ outputs=output_display
519
+ )
520
+
521
+ # Download and clear
522
+ download_btn.click(fn=download_all_professional, outputs=[download_file, stats_display])
523
+ clear_btn.click(fn=clear_all, outputs=[output_display, download_file, stats_display])
524
+
525
+ if __name__ == "__main__":
526
+ demo.launch(debug=True, share=False)