-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
82 lines (70 loc) · 2.83 KB
/
app.py
File metadata and controls
82 lines (70 loc) · 2.83 KB
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
# Copyright Volkan Sah Kücükbudak
# Only for academic research!
import os
config = load_config()
config = {
"environment": {
"cache_dir": os.getenv("CACHE_DIR", "/tmp/default_cache"),
"max_temp_files": int(os.getenv("MAX_TEMP_FILES", "50"))
},
# ... andere Werte
}
# Verwende die Config-Werte
os.environ["MPLCONFIGDIR"] = config["environment"]["cache_dir"]
MAX_FILE_SIZE = config["security"]["max_file_size_mb"] * 1024 * 1024
# Matplotlib Cache-Konfiguration für Huggingface Spaces
os.environ['MPLCONFIGDIR'] = '/tmp/matplotlib-cache'
os.makedirs(os.environ['MPLCONFIGDIR'], exist_ok=True)
import gradio as gr
import json
from pathlib import Path
from modules.model_handler import AI_MODELS, generate_code
from modules.config_loader import load_config
# Huggingface Spaces-Konfiguration
HF_SPACE = os.getenv('HF_SPACE', False)
TEMP_DIR = Path('/tmp') if HF_SPACE else Path(__file__).parent / 'temp'
TEMP_DIR.mkdir(exist_ok=True)
# UI-Komponenten
def create_interface():
with gr.Blocks(title="KI-Assistent Generator") as demo:
gr.Markdown("# 🚀 KI-Assistent Generator")
with gr.Row():
with gr.Column(scale=2):
task_input = gr.Textbox(label="Aufgabenbeschreibung", placeholder="Beschreibe deinen gewünschten Assistenten...")
api_key = gr.Textbox(label="API-Key", type="password")
language = gr.Dropdown(["python", "php", "javascript"], label="Programmiersprache")
generate_btn = gr.Button("Generieren", variant="primary")
with gr.Column(scale=3):
code_output = gr.Code(label="Generierter Code", language="python", interactive=True)
status = gr.Textbox(label="Status", interactive=False)
generate_btn.click(
generate_code_wrapper,
inputs=[task_input, api_key, language],
outputs=[code_output, status]
)
return demo
# Hilfsfunktion für Code-Generierung
def generate_code_wrapper(task_input, api_key, language):
try:
if not task_input.strip():
return "", "⚠️ Bitte Aufgabenbeschreibung eingeben!"
if not api_key.strip():
return "", "🔑 API-Key wird benötigt!"
generated_code = generate_code(
task_input=task_input,
api_key=api_key,
language=language,
hf_space=HF_SPACE,
temp_dir=str(TEMP_DIR)
)
return generated_code, "✅ Code erfolgreich generiert!"
except Exception as e:
return "", f"❌ Fehler: {str(e)}"
if __name__ == "__main__":
config = load_config()
interface = create_interface()
interface.launch(
server_name="0.0.0.0",
server_port=int(os.getenv('PORT', 7860)),
share=config.get('share', False)
)