drdudddd commited on
Commit
d7ecf02
Β·
verified Β·
1 Parent(s): 56e7ce6

Upload 2 files

Browse files
Files changed (2) hide show
  1. app_2.py +132 -0
  2. requirements_2.txt +4 -0
app_2.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_client import Client, handle_file
3
+
4
+ # ────────────────────────────────────────────────
5
+ # Konfiguration der drei Spaces
6
+ # ────────────────────────────────────────────────
7
+ spaces = {
8
+ "Omni Image Editor": {
9
+ "url": "https://selfit-camera-omni-image-editor.hf.space/",
10
+ "api_name": "/text_to_image_interface",
11
+ "inputs": ["prompt", "aspect_ratio"],
12
+ "default": {"aspect_ratio": "16:9"},
13
+ "needs_image": False,
14
+ "note": "Text-to-Image – braucht nur Prompt"
15
+ },
16
+ "FireRed Image Edit": {
17
+ "url": "https://prithivmlmods-firered-image-edit-1-0-fast.hf.space/",
18
+ "api_name": "/predict", # hΓ€ufigster Name – ggf. spΓ€ter anpassen
19
+ "inputs": ["image", "prompt", "strength", "steps"],
20
+ "default": {"strength": 0.65, "steps": 28},
21
+ "needs_image": True,
22
+ "note": "Image-to-Image Edit – braucht Referenzbild + Prompt"
23
+ },
24
+ "Ana2": {
25
+ "url": "https://galaxydude2-ana2.hf.space/",
26
+ "api_name": "/predict", # sehr wahrscheinlich /predict
27
+ "inputs": ["image"],
28
+ "default": {},
29
+ "needs_image": True,
30
+ "note": "Analyzer (Nudity/NSFW?) – braucht nur Bild, kein Prompt"
31
+ }
32
+ }
33
+
34
+ # ────────────────────────────────────────────────
35
+ # Hauptfunktion – je nach Space unterschiedlicher Aufruf
36
+ # ────────────────────────────────────────────────
37
+ def run_space(selected_space, prompt_text, image_input=None):
38
+ if selected_space not in spaces:
39
+ return None, "UngΓΌltiger Space ausgewΓ€hlt"
40
+
41
+ cfg = spaces[selected_space]
42
+ status = f"β†’ {selected_space} | "
43
+
44
+ # PrΓΌfen ob Bild benΓΆtigt wird
45
+ if cfg["needs_image"] and image_input is None:
46
+ return None, status + "Dieser Space braucht ein Referenzbild"
47
+
48
+ try:
49
+ client = Client(cfg["url"])
50
+
51
+ kwargs = cfg["default"].copy()
52
+
53
+ # Prompt nur bei Spaces ΓΌbergeben, die ihn erwarten
54
+ if "prompt" in cfg["inputs"] and prompt_text.strip():
55
+ kwargs["prompt"] = prompt_text.strip()
56
+
57
+ # Bild ΓΌbergeben, wenn nΓΆtig
58
+ if cfg["needs_image"] and image_input:
59
+ kwargs["image"] = handle_file(image_input)
60
+
61
+ # Aspect Ratio nur bei Omni
62
+ if selected_space == "Omni Image Editor" and "aspect_ratio" in cfg["inputs"]:
63
+ kwargs["aspect_ratio"] = "16:9" # fest codiert wie gewΓΌnscht
64
+
65
+ # API-Aufruf
66
+ result = client.predict(**kwargs, api_name=cfg["api_name"])
67
+
68
+ # Ergebnis verarbeiten
69
+ if isinstance(result, (list, tuple)):
70
+ # hΓ€ufigstes Muster: (image, status_str, ...) oder nur image
71
+ for item in result:
72
+ if hasattr(item, 'save'): # PIL Image
73
+ return item, status + "Erfolg"
74
+ if isinstance(item, str) and len(item) > 10 and "http" in item:
75
+ return item, status + "Erfolg (Link)"
76
+ elif hasattr(result, 'save'): # direkt PIL
77
+ return result, status + "Erfolg"
78
+ else:
79
+ return None, status + f"Unbekanntes Ergebnis-Format: {type(result)}"
80
+
81
+ except Exception as e:
82
+ err_msg = str(e).replace(cfg["url"], "[URL]").replace(cfg["api_name"], "[API]")
83
+ return None, status + f"Fehler: {err_msg}"
84
+
85
+ # ────────────────────────────────────────────────
86
+ # Gradio OberflΓ€che
87
+ # ────────────────────────────────────────────────
88
+ with gr.Blocks() as demo:
89
+ gr.Markdown("# Multi-Space Quick Launcher\nOmni Β· FireRed Edit Β· Ana2")
90
+
91
+ with gr.Row():
92
+ space_choice = gr.Dropdown(
93
+ choices=list(spaces.keys()),
94
+ value="Omni Image Editor",
95
+ label="Space auswΓ€hlen"
96
+ )
97
+
98
+ with gr.Row():
99
+ with gr.Column(scale=3):
100
+ prompt_input = gr.Textbox(
101
+ label="Prompt (wird nur bei Omni & FireRed genutzt)",
102
+ placeholder="1 oder sexy woman nude beach oder eigener Text",
103
+ lines=2
104
+ )
105
+ with gr.Column(scale=1):
106
+ generate_btn = gr.Button("AusfΓΌhren", variant="primary")
107
+
108
+ image_input = gr.Image(
109
+ label="Referenzbild (nur FireRed & Ana2 benΓΆtigt)",
110
+ type="filepath",
111
+ source="upload"
112
+ )
113
+
114
+ output_image = gr.Image(label="Ergebnis")
115
+ status_text = gr.Textbox(label="Status / Fehlermeldung", interactive=False, lines=3)
116
+
117
+ # Info-Box unten
118
+ gr.Markdown("""
119
+ **Hinweise:**
120
+ β€’ **Omni** β†’ reiner Text-to-Image (16:9 fest), braucht **kein** Bild
121
+ β€’ **FireRed** β†’ Edit-Modell, braucht fast immer ein **Startbild**
122
+ β€’ **Ana2** β†’ wahrscheinlich NSFW/Nudity-Analyzer, braucht nur Bild, ignoriert Prompt
123
+ β€’ Bei Fehlern: API-Name oder Parameter haben sich geΓ€ndert β†’ `client.view_api()` lokal ausfΓΌhren
124
+ """)
125
+
126
+ generate_btn.click(
127
+ fn=run_space,
128
+ inputs=[space_choice, prompt_input, image_input],
129
+ outputs=[output_image, status_text]
130
+ )
131
+
132
+ demo.launch()
requirements_2.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ gradio_client
3
+ pillow
4
+ requests