Update Text to Image: Format dropdown, remove Aspect Ratio
Browse files- Replace Style dropdown with Format dropdown
- Options: image (generate_image_5), multi (generate_image_multi_5), 3d (generate_image_3d)
- Remove Aspect Ratio dropdown
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- app.py +3 -5
- src/services/image.py +13 -23
- src/ui/handlers.py +2 -4
- src/ui/tabs.py +6 -15
app.py
CHANGED
|
@@ -23,13 +23,12 @@ def create_demo():
|
|
| 23 |
theme=gr.themes.Soft()
|
| 24 |
) as demo:
|
| 25 |
gr.Markdown("# StackNet 1:1 Preview Demo")
|
| 26 |
-
gr.Markdown("AI-powered media generation - Images, Videos, and Music")
|
| 27 |
|
| 28 |
# API Key input at the top
|
| 29 |
with gr.Accordion("Settings", open=False):
|
| 30 |
api_key = gr.Textbox(
|
| 31 |
-
label="StackNet
|
| 32 |
-
placeholder="Enter your
|
| 33 |
type="password"
|
| 34 |
)
|
| 35 |
|
|
@@ -62,8 +61,7 @@ def create_demo():
|
|
| 62 |
fn=Handlers.generate_image,
|
| 63 |
inputs=[
|
| 64 |
tabs["text_to_image"]["prompt"],
|
| 65 |
-
tabs["text_to_image"]["
|
| 66 |
-
tabs["text_to_image"]["aspect_ratio"],
|
| 67 |
api_key
|
| 68 |
],
|
| 69 |
outputs=[
|
|
|
|
| 23 |
theme=gr.themes.Soft()
|
| 24 |
) as demo:
|
| 25 |
gr.Markdown("# StackNet 1:1 Preview Demo")
|
|
|
|
| 26 |
|
| 27 |
# API Key input at the top
|
| 28 |
with gr.Accordion("Settings", open=False):
|
| 29 |
api_key = gr.Textbox(
|
| 30 |
+
label="StackNet Key",
|
| 31 |
+
placeholder="Enter your key (e.g., sn_xxxxx)",
|
| 32 |
type="password"
|
| 33 |
)
|
| 34 |
|
|
|
|
| 61 |
fn=Handlers.generate_image,
|
| 62 |
inputs=[
|
| 63 |
tabs["text_to_image"]["prompt"],
|
| 64 |
+
tabs["text_to_image"]["format_type"],
|
|
|
|
| 65 |
api_key
|
| 66 |
],
|
| 67 |
outputs=[
|
src/services/image.py
CHANGED
|
@@ -36,43 +36,33 @@ class ImageService:
|
|
| 36 |
async def generate_image(
|
| 37 |
self,
|
| 38 |
prompt: str,
|
| 39 |
-
|
| 40 |
-
aspect_ratio: Optional[str] = None,
|
| 41 |
on_progress: Optional[Callable[[float, str], None]] = None
|
| 42 |
) -> List[GeneratedImage]:
|
| 43 |
"""
|
| 44 |
-
Generate image from a text prompt
|
| 45 |
|
| 46 |
Args:
|
| 47 |
prompt: Description of desired image
|
| 48 |
-
|
| 49 |
-
|
| 50 |
on_progress: Callback for progress updates
|
| 51 |
|
| 52 |
Returns:
|
| 53 |
List of generated images
|
| 54 |
"""
|
| 55 |
-
|
| 56 |
-
if
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
width, height = 1280, 720
|
| 63 |
-
elif aspect_ratio == "9:16":
|
| 64 |
-
width, height = 720, 1280
|
| 65 |
-
elif aspect_ratio == "4:3":
|
| 66 |
-
width, height = 1024, 768
|
| 67 |
-
elif aspect_ratio == "3:4":
|
| 68 |
-
width, height = 768, 1024
|
| 69 |
|
| 70 |
result = await self.client.submit_tool_task(
|
| 71 |
-
tool_name=
|
| 72 |
parameters={
|
| 73 |
-
"prompt":
|
| 74 |
-
"width": width,
|
| 75 |
-
"height": height
|
| 76 |
},
|
| 77 |
on_progress=on_progress
|
| 78 |
)
|
|
|
|
| 36 |
async def generate_image(
|
| 37 |
self,
|
| 38 |
prompt: str,
|
| 39 |
+
format_type: str = "image",
|
|
|
|
| 40 |
on_progress: Optional[Callable[[float, str], None]] = None
|
| 41 |
) -> List[GeneratedImage]:
|
| 42 |
"""
|
| 43 |
+
Generate image from a text prompt.
|
| 44 |
|
| 45 |
Args:
|
| 46 |
prompt: Description of desired image
|
| 47 |
+
format_type: Format type - "image" (generate_image_5),
|
| 48 |
+
"multi" (generate_image_multi_5), or "3d" (generate_image_3d)
|
| 49 |
on_progress: Callback for progress updates
|
| 50 |
|
| 51 |
Returns:
|
| 52 |
List of generated images
|
| 53 |
"""
|
| 54 |
+
# Select tool based on format type
|
| 55 |
+
if format_type == "multi":
|
| 56 |
+
tool_name = "generate_image_multi_5"
|
| 57 |
+
elif format_type == "3d":
|
| 58 |
+
tool_name = "generate_image_3d"
|
| 59 |
+
else:
|
| 60 |
+
tool_name = "generate_image_5"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
result = await self.client.submit_tool_task(
|
| 63 |
+
tool_name=tool_name,
|
| 64 |
parameters={
|
| 65 |
+
"prompt": prompt
|
|
|
|
|
|
|
| 66 |
},
|
| 67 |
on_progress=on_progress
|
| 68 |
)
|
src/ui/handlers.py
CHANGED
|
@@ -183,8 +183,7 @@ class Handlers:
|
|
| 183 |
@staticmethod
|
| 184 |
def generate_image(
|
| 185 |
prompt: str,
|
| 186 |
-
|
| 187 |
-
aspect_ratio: str,
|
| 188 |
api_key: str = ""
|
| 189 |
) -> Tuple[Optional[str], str]:
|
| 190 |
"""Handle text-to-image generation."""
|
|
@@ -204,8 +203,7 @@ class Handlers:
|
|
| 204 |
images = loop.run_until_complete(
|
| 205 |
service.generate_image(
|
| 206 |
prompt=prompt,
|
| 207 |
-
|
| 208 |
-
aspect_ratio=aspect_ratio
|
| 209 |
)
|
| 210 |
)
|
| 211 |
|
|
|
|
| 183 |
@staticmethod
|
| 184 |
def generate_image(
|
| 185 |
prompt: str,
|
| 186 |
+
format_type: str,
|
|
|
|
| 187 |
api_key: str = ""
|
| 188 |
) -> Tuple[Optional[str], str]:
|
| 189 |
"""Handle text-to-image generation."""
|
|
|
|
| 203 |
images = loop.run_until_complete(
|
| 204 |
service.generate_image(
|
| 205 |
prompt=prompt,
|
| 206 |
+
format_type=format_type
|
|
|
|
| 207 |
)
|
| 208 |
)
|
| 209 |
|
src/ui/tabs.py
CHANGED
|
@@ -156,19 +156,11 @@ def create_text_to_image_tab():
|
|
| 156 |
lines=3
|
| 157 |
)
|
| 158 |
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
scale=1
|
| 165 |
-
)
|
| 166 |
-
aspect_ratio = gr.Dropdown(
|
| 167 |
-
label="Aspect Ratio",
|
| 168 |
-
choices=["1:1", "16:9", "9:16", "4:3", "3:4"],
|
| 169 |
-
value="1:1",
|
| 170 |
-
scale=1
|
| 171 |
-
)
|
| 172 |
|
| 173 |
generate_btn = gr.Button("Generate Image", variant="primary", size="lg")
|
| 174 |
|
|
@@ -178,8 +170,7 @@ def create_text_to_image_tab():
|
|
| 178 |
|
| 179 |
return {
|
| 180 |
"prompt": prompt,
|
| 181 |
-
"
|
| 182 |
-
"aspect_ratio": aspect_ratio,
|
| 183 |
"generate_btn": generate_btn,
|
| 184 |
"status": status,
|
| 185 |
"output_image": output_image
|
|
|
|
| 156 |
lines=3
|
| 157 |
)
|
| 158 |
|
| 159 |
+
format_type = gr.Dropdown(
|
| 160 |
+
label="Format",
|
| 161 |
+
choices=["image", "multi", "3d"],
|
| 162 |
+
value="image"
|
| 163 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
generate_btn = gr.Button("Generate Image", variant="primary", size="lg")
|
| 166 |
|
|
|
|
| 170 |
|
| 171 |
return {
|
| 172 |
"prompt": prompt,
|
| 173 |
+
"format_type": format_type,
|
|
|
|
| 174 |
"generate_btn": generate_btn,
|
| 175 |
"status": status,
|
| 176 |
"output_image": output_image
|