LucanDerLurch commited on
Commit
494dcd4
·
verified ·
1 Parent(s): 0452b8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -52
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
- # Unser eigenes Design (CSS) - Dunkel, giftgrün und atmosphärisch!
11
- eigenes_design = """
12
- body, .gradio-container { background-color: #0a0a0a !important; color: #d1d5db !important; }
13
- h1 { color: #39ff14 !important; text-align: center; text-transform: uppercase; text-shadow: 0 0 10px #39ff14; font-weight: bold;}
14
- .rucksack-box { border: 2px solid #8b0000 !important; background: #1a1a1a !important; padding: 10px; border-radius: 5px; color: #ffaa00 !important; font-family: monospace; font-size: 1.2em;}
15
- button { background-color: #8b0000 !important; color: white !important; font-weight: bold !important; border: 1px solid #ff0000 !important; }
16
- button:hover { background-color: #ff0000 !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  """
18
 
19
- def spiel_zug(nachricht, verlauf, aktueller_rucksack):
20
- # Wir sagen der KI streng, dass sie das Inventar mit verwalten muss
21
- system_prompt = f"""Du bist der Spielleiter von 'Zombie Go'.
22
- Der Spieler hat aktuell diesen Rucksack: {aktueller_rucksack}.
23
- WICHTIG: Der Spieler kann nur Dinge nutzen, die im Rucksack sind! Erfinde keine Waffen für ihn.
24
- Füge neu gefundene Gegenstände oder gesammeltes 'Go' logisch zum Rucksack hinzu.
25
- Aktion des Spielers: '{nachricht}'.
 
26
 
27
- Antworte EXAKT in dieser Form (ohne Ausnahmen):
28
- STORY: [Beschreibe in max 3 spannenden Sätzen, was passiert]
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 = "Die Verbindung stottert... die KI schnappt nach Luft."
46
  neuer_rucksack = aktueller_rucksack
47
 
48
- # Bild KI (mit düsteren englischen Suchbegriffen)
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
- verlauf.append((nachricht, story_text))
56
 
57
- # Rucksack-Text für die Oberfläche formatieren
58
- rucksack_anzeige = f"**🎒 DEIN RUCKSACK:** {neuer_rucksack}"
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
- # Wir laden das eigene CSS direkt in den Baukasten
65
- with gr.Blocks(css=eigenes_design, theme=gr.themes.Monochrome()) as spiel_oberflaeche:
66
- gr.Markdown("# 🧟 ZOMBIE GO")
67
-
68
- # State (unsichtbarer Speicher) für deinen Start-Rucksack
69
- rucksack_speicher = gr.State("Taschenlampe, leere Wasserflasche | GO: 0")
70
-
71
- with gr.Row():
72
- with gr.Column(scale=1):
73
- szene_bild = gr.Image(label="Kamera-Feed", type="pil")
74
- # Die sichtbare Anzeige für das Inventar
75
- rucksack_ui = gr.Markdown("**🎒 DEIN RUCKSACK:** Taschenlampe, leere Wasserflasche | GO: 0", elem_classes="rucksack-box")
76
-
77
- with gr.Column(scale=1):
78
- chat = gr.Chatbot(label="Überlebens-Logbuch", height=350)
79
- eingabe = gr.Textbox(label="Aktion", placeholder="Was tust du? (z.B. Ich suche nach Waffen)")
80
- senden_btn = gr.Button("⚔️ Aktion ausführen")
81
 
82
- # Verknüpfungen der Knöpfe
83
  senden_btn.click(
84
  spiel_zug,
85
- inputs=[eingabe, chat, rucksack_speicher],
86
- outputs=[chat, szene_bild, eingabe, rucksack_ui, rucksack_speicher]
87
  )
88
  eingabe.submit(
89
  spiel_zug,
90
- inputs=[eingabe, chat, rucksack_speicher],
91
- outputs=[chat, szene_bild, eingabe, rucksack_ui, rucksack_speicher]
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()