Spaces:
Sleeping
Update app.py
Browse files# Fügen Sie diesen Import am Anfang von app.py hinzu, falls er fehlt
from transformers import BitsAndBytesConfig
try:
print(f"--- Starte Ladevorgang für {MODEL_NAME} mit maximaler Optimierung ---")
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
# Auf CPU ignorieren diese Parameter oft, aber sie helfen,
bnb_4bit_compute_dtype=DTYPE
)
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForCausalLM.from_pretrained(
MODEL_NAME,
quantization_config=bnb_config, # Versucht, es als 4-Bit zu laden
device_map="auto",
low_cpu_mem_usage=True,
trust_remote_code=True,
)
# Erstellt die Pipeline... (Rest des Codes wie gehabt)
# ...
print(f"Modell '{MODEL_NAME}' erfolgreich geladen und Pipeline erstellt.")
except Exception as e:
# ... (Rest des except-Blocks wie gehabt)
print(f"FATALER FEHLER beim Laden des Modells {MODEL_NAME}: {e}")
print("--- Verwende GPT-2 als langsamen Platzhalter ---")
coco_pipe = pipeline("text-generation", model="gpt2")
|
@@ -1,82 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from huggingface_hub import InferenceClient
|
| 3 |
-
import os
|
| 4 |
-
import time
|
| 5 |
-
|
| 6 |
-
# Verbindung zur KI (Mock-KI für Demo)
|
| 7 |
-
hf_token = os.getenv("HF_TOKEN")
|
| 8 |
-
code_client = InferenceClient("CustomCodeAI/CodeGenModel", token=hf_token)
|
| 9 |
-
image_client = InferenceClient("ImageGenAI/ImageXModel", token=hf_token)
|
| 10 |
-
video_client = InferenceClient("VideoGenAI/VideoZModel", token=hf_token)
|
| 11 |
-
|
| 12 |
-
# Modus 1: Code erstellen und testen (Create-Modus)
|
| 13 |
-
def create_mode_fn(prompt):
|
| 14 |
-
try:
|
| 15 |
-
time.sleep(2) # Simulierte Ladeanimation
|
| 16 |
-
output_code = "<html><body><h1>Dies ist ein Beispiel</h1></body></html>" # DUMMY-Code für Demo
|
| 17 |
-
return f"<iframe width='100%' height='500px' srcdoc='{output_code}'></iframe>"
|
| 18 |
-
except Exception as e:
|
| 19 |
-
return f"Fehler beim Generieren: {str(e)}"
|
| 20 |
-
|
| 21 |
-
# Modus 2: Bild generieren (ImageX-Modus)
|
| 22 |
-
def imagex_mode_fn(prompt, animate=False):
|
| 23 |
-
try:
|
| 24 |
-
image_path = "/tmp/generated_image_demo.png" # Mock-Pfad
|
| 25 |
-
# Dummy-Implementierung für das Bild
|
| 26 |
-
with open(image_path, "wb") as img_file:
|
| 27 |
-
img_file.write(b"FAKE_IMAGE_DATA")
|
| 28 |
-
|
| 29 |
-
if animate:
|
| 30 |
-
return image_path, "Video-Modus: Animation gestartet..."
|
| 31 |
-
return image_path, ""
|
| 32 |
-
except Exception as e:
|
| 33 |
-
return None, f"Fehler beim Generieren: {str(e)}"
|
| 34 |
-
|
| 35 |
-
# Modus 3: Animationsvideo erstellen (VideoZ-Modus)
|
| 36 |
-
def videoz_mode_fn(image_path):
|
| 37 |
-
try:
|
| 38 |
-
video_path = "/tmp/generated_video_demo.mp4" # Mock-Pfad
|
| 39 |
-
# Dummy-Datei für Demo
|
| 40 |
-
with open(video_path, "wb") as vid_file:
|
| 41 |
-
vid_file.write(b"FAKE_VIDEO_DATA")
|
| 42 |
-
return video_path
|
| 43 |
-
except Exception as e:
|
| 44 |
-
return f"Fehler beim Generieren: {str(e)}"
|
| 45 |
-
|
| 46 |
-
# Styling und Design
|
| 47 |
-
custom_css = """
|
| 48 |
-
.gradio-container {
|
| 49 |
-
background-color: #e0f7fa !important;
|
| 50 |
-
font-family: 'Arial', sans-serif !important;
|
| 51 |
-
}
|
| 52 |
-
.gradio-header, .gradio-footer { display: none !important; }
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
# App-Design
|
| 56 |
-
with gr.Blocks(title="Modulare Coco-App") as demo:
|
| 57 |
-
with gr.Tab("Create-Modus (Code erstellen und testen)"):
|
| 58 |
-
gr.Markdown("**Create-Modus**: Generiere und teste eigenen Code (HTML, CSS, JS) ✨.")
|
| 59 |
-
create_input = gr.Textbox(placeholder="Beschreibe, was die KI erstellen soll (z. B. 'Endless Runner')", lines=2)
|
| 60 |
-
create_button = gr.Button("Generieren")
|
| 61 |
-
create_output = gr.HTML()
|
| 62 |
-
create_button.click(create_mode_fn, inputs=create_input, outputs=create_output)
|
| 63 |
-
|
| 64 |
-
with gr.Tab("ImageX-Modus (Bild generieren)"):
|
| 65 |
-
gr.Markdown("**ImageX-Modus**: Generiere Bilder und wandle sie in Animationen um 🎨.")
|
| 66 |
-
imagex_input = gr.Textbox(placeholder="Beschreibe das Bild", lines=2)
|
| 67 |
-
imagex_animate = gr.Checkbox(label="Direkt animieren?", value=False)
|
| 68 |
-
imagex_button = gr.Button("Bild generieren")
|
| 69 |
-
imagex_output = gr.Image(interactive=False)
|
| 70 |
-
imagex_animation = gr.Textbox(interactive=False)
|
| 71 |
-
imagex_button.click(imagex_mode_fn, inputs=[imagex_input, imagex_animate], outputs=[imagex_output, imagex_animation])
|
| 72 |
-
|
| 73 |
-
with gr.Tab("VideoZ-Modus (Video animieren)"):
|
| 74 |
-
gr.Markdown("**VideoZ-Modus**: Erstelle animierte Videos aus KI-generierten oder hochgeladenen Bildern 🎥.")
|
| 75 |
-
videoz_input = gr.File(label="Bild hochladen oder wählen")
|
| 76 |
-
videoz_button = gr.Button("Video animieren")
|
| 77 |
-
videoz_output = gr.Video()
|
| 78 |
-
videoz_button.click(videoz_mode_fn, inputs=videoz_input, outputs=videoz_output)
|
| 79 |
-
|
| 80 |
-
# Start der App
|
| 81 |
-
if __name__ == "__main__":
|
| 82 |
-
demo.launch(css=custom_css)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|