Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,92 +3,114 @@ import gradio as gr
|
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
token = os.environ.get("HF_TOKEN")
|
| 6 |
-
|
| 7 |
text_client = InferenceClient("google/gemma-1.1-7b-it", token=token)
|
| 8 |
bild_client = InferenceClient("stabilityai/stable-diffusion-xl-base-1.0", token=token)
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
.
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
"""
|
| 18 |
|
| 19 |
-
def spiel_zug(nachricht,
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
-
Antworte
|
| 28 |
-
STORY: [
|
| 29 |
-
RUCKSACK: [Liste der Items] | GO: [Anzahl]"""
|
| 30 |
|
| 31 |
try:
|
| 32 |
antwort = text_client.text_generation(system_prompt, max_new_tokens=200)
|
| 33 |
|
| 34 |
-
# Split (Text zerteilen): Wir trennen Story und Rucksack am Wort "RUCKSACK:"
|
| 35 |
if "RUCKSACK:" in antwort:
|
| 36 |
teile = antwort.split("RUCKSACK:")
|
| 37 |
story_text = teile[0].replace("STORY:", "").strip()
|
| 38 |
neuer_rucksack = teile[1].strip()
|
| 39 |
else:
|
| 40 |
-
# Falls die KI den Befehl vermasselt, behalten wir den alten Rucksack
|
| 41 |
story_text = antwort.replace("STORY:", "").strip()
|
| 42 |
neuer_rucksack = aktueller_rucksack
|
| 43 |
-
|
| 44 |
except Exception as e:
|
| 45 |
-
story_text = "
|
| 46 |
neuer_rucksack = aktueller_rucksack
|
| 47 |
|
| 48 |
-
|
| 49 |
-
bild_prompt = f"dark zombie apocalypse survival scene, first person view, {nachricht}, eerie green lighting, highly detailed, 8k resolution"
|
| 50 |
try:
|
| 51 |
bild = bild_client.text_to_image(bild_prompt)
|
| 52 |
except:
|
| 53 |
bild = None
|
| 54 |
|
| 55 |
-
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
# Gibt alles zurück: Chat, Bild, leeres Textfeld, schicke Anzeige, unsichtbarer Speicher
|
| 61 |
-
return verlauf, bild, "", rucksack_anzeige, neuer_rucksack
|
| 62 |
|
| 63 |
|
| 64 |
-
|
| 65 |
-
with gr.
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
senden_btn = gr.Button("⚔️ Aktion ausführen")
|
| 81 |
|
| 82 |
-
#
|
| 83 |
senden_btn.click(
|
| 84 |
spiel_zug,
|
| 85 |
-
inputs=[eingabe,
|
| 86 |
-
outputs=[
|
| 87 |
)
|
| 88 |
eingabe.submit(
|
| 89 |
spiel_zug,
|
| 90 |
-
inputs=[eingabe,
|
| 91 |
-
outputs=[
|
| 92 |
)
|
| 93 |
|
| 94 |
spiel_oberflaeche.launch()
|
|
|
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
token = os.environ.get("HF_TOKEN")
|
|
|
|
| 6 |
text_client = InferenceClient("google/gemma-1.1-7b-it", token=token)
|
| 7 |
bild_client = InferenceClient("stabilityai/stable-diffusion-xl-base-1.0", token=token)
|
| 8 |
|
| 9 |
+
# Das absolute krasse Custom CSS (Terminal-Style)
|
| 10 |
+
hartes_design = """
|
| 11 |
+
@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap');
|
| 12 |
+
|
| 13 |
+
body, .gradio-container {
|
| 14 |
+
background-color: #050505 !important;
|
| 15 |
+
color: #33ff33 !important;
|
| 16 |
+
font-family: 'Share Tech Mono', monospace !important;
|
| 17 |
+
background-image: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(51, 255, 51, 0.05) 2px, rgba(51, 255, 51, 0.05) 4px);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
.haupt-terminal {
|
| 21 |
+
max-width: 800px !important;
|
| 22 |
+
margin: 0 auto !important;
|
| 23 |
+
border: 2px solid #33ff33 !important;
|
| 24 |
+
box-shadow: 0 0 20px rgba(51, 255, 51, 0.2);
|
| 25 |
+
padding: 20px !important;
|
| 26 |
+
background: #000 !important;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
h1 { color: #33ff33 !important; text-align: center; text-transform: uppercase; text-shadow: 0 0 10px #33ff33; font-size: 2.5em !important; margin-bottom: 20px !important;}
|
| 30 |
+
|
| 31 |
+
.rucksack-anzeige {
|
| 32 |
+
border: 1px dashed #ff3333 !important;
|
| 33 |
+
padding: 10px !important;
|
| 34 |
+
color: #ff3333 !important;
|
| 35 |
+
text-align: center;
|
| 36 |
+
margin-bottom: 20px !important;
|
| 37 |
+
text-transform: uppercase;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.output-bild { border: 2px solid #33ff33 !important; border-radius: 0 !important; margin-bottom: 15px !important;}
|
| 41 |
+
.output-text { color: #fff !important; font-size: 1.2em !important; line-height: 1.5 !important; padding: 15px !important; background: rgba(51,255,51,0.1) !important; border-left: 5px solid #33ff33 !important;}
|
| 42 |
+
|
| 43 |
+
input, textarea { background: #111 !important; color: #33ff33 !important; border: 1px solid #33ff33 !important; font-family: 'Share Tech Mono', monospace !important; font-size: 1.2em !important;}
|
| 44 |
+
button { background: #33ff33 !important; color: #000 !important; border: none !important; font-weight: bold !important; text-transform: uppercase !important; font-size: 1.2em !important; padding: 10px !important; box-shadow: 0 0 10px #33ff33 !important;}
|
| 45 |
+
button:hover { background: #fff !important; color: #000 !important; box-shadow: 0 0 20px #fff !important;}
|
| 46 |
"""
|
| 47 |
|
| 48 |
+
def spiel_zug(nachricht, aktueller_rucksack):
|
| 49 |
+
if not nachricht:
|
| 50 |
+
return None, "Du musst schon was tun!", aktueller_rucksack, f"🎒 INVENTAR: {aktueller_rucksack}", ""
|
| 51 |
+
|
| 52 |
+
system_prompt = f"""Du bist 'Zombie Go'.
|
| 53 |
+
Inventar des Spielers: {aktueller_rucksack}.
|
| 54 |
+
Regel: Der Spieler darf NUR Dinge nutzen, die im Inventar sind.
|
| 55 |
+
Aktion: '{nachricht}'.
|
| 56 |
|
| 57 |
+
Antworte in diesem Format:
|
| 58 |
+
STORY: [Max 3 Sätze, düster, beschreibe die Folgen der Aktion]
|
| 59 |
+
RUCKSACK: [Aktualisierte Liste der Items] | GO: [Anzahl]"""
|
| 60 |
|
| 61 |
try:
|
| 62 |
antwort = text_client.text_generation(system_prompt, max_new_tokens=200)
|
| 63 |
|
|
|
|
| 64 |
if "RUCKSACK:" in antwort:
|
| 65 |
teile = antwort.split("RUCKSACK:")
|
| 66 |
story_text = teile[0].replace("STORY:", "").strip()
|
| 67 |
neuer_rucksack = teile[1].strip()
|
| 68 |
else:
|
|
|
|
| 69 |
story_text = antwort.replace("STORY:", "").strip()
|
| 70 |
neuer_rucksack = aktueller_rucksack
|
|
|
|
| 71 |
except Exception as e:
|
| 72 |
+
story_text = "Systemfehler. Verbindung zur Realität unterbrochen."
|
| 73 |
neuer_rucksack = aktueller_rucksack
|
| 74 |
|
| 75 |
+
bild_prompt = f"dark zombie apocalypse survival scene, first person view, {nachricht}, eerie green lighting, highly detailed, retro game style"
|
|
|
|
| 76 |
try:
|
| 77 |
bild = bild_client.text_to_image(bild_prompt)
|
| 78 |
except:
|
| 79 |
bild = None
|
| 80 |
|
| 81 |
+
rucksack_ui_text = f"🎒 INVENTAR: {neuer_rucksack}"
|
| 82 |
|
| 83 |
+
# Wir geben das Bild, die Story, den neuen Speicher, die UI-Anzeige und leeren das Textfeld
|
| 84 |
+
return bild, story_text, neuer_rucksack, rucksack_ui_text, ""
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
|
| 87 |
+
with gr.Blocks(css=hartes_design, theme=gr.themes.Base()) as spiel_oberflaeche:
|
| 88 |
+
with gr.Column(elem_classes="haupt-terminal"):
|
| 89 |
+
gr.Markdown("# 🧟 ZOMBIE GO")
|
| 90 |
+
|
| 91 |
+
rucksack_speicher = gr.State("Brecheisen, leere Wasserflasche | GO: 0")
|
| 92 |
+
rucksack_ui = gr.Markdown("🎒 INVENTAR: Brecheisen, leere Wasserflasche | GO: 0", elem_classes="rucksack-anzeige")
|
| 93 |
+
|
| 94 |
+
# Ein Block für die Ausgabe (Bild + Text darunter)
|
| 95 |
+
szene_bild = gr.Image(label="Kamera-Feed", type="pil", elem_classes="output-bild")
|
| 96 |
+
story_ausgabe = gr.Markdown("*Warte auf Eingabe...*", elem_classes="output-text")
|
| 97 |
+
|
| 98 |
+
gr.Markdown("---")
|
| 99 |
+
|
| 100 |
+
# Eingabe-Bereich
|
| 101 |
+
eingabe = gr.Textbox(label="", placeholder="Aktion eingeben... (z.B. Umschauen)", lines=1)
|
| 102 |
+
senden_btn = gr.Button("▶ AUSFÜHREN")
|
|
|
|
| 103 |
|
| 104 |
+
# Auslöser
|
| 105 |
senden_btn.click(
|
| 106 |
spiel_zug,
|
| 107 |
+
inputs=[eingabe, rucksack_speicher],
|
| 108 |
+
outputs=[szene_bild, story_ausgabe, rucksack_speicher, rucksack_ui, eingabe]
|
| 109 |
)
|
| 110 |
eingabe.submit(
|
| 111 |
spiel_zug,
|
| 112 |
+
inputs=[eingabe, rucksack_speicher],
|
| 113 |
+
outputs=[szene_bild, story_ausgabe, rucksack_speicher, rucksack_ui, eingabe]
|
| 114 |
)
|
| 115 |
|
| 116 |
spiel_oberflaeche.launch()
|