Add Gradio workflow app script and workflow JSON configuration
Browse files- run.py +56 -0
- workflow.json +1 -0
run.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def describe_product(image) -> str:
|
| 8 |
+
if image is None:
|
| 9 |
+
return "a premium product"
|
| 10 |
+
img_path = image.get("path") if isinstance(image, dict) else str(image)
|
| 11 |
+
img_url = image.get("url", "") if isinstance(image, dict) else str(image)
|
| 12 |
+
try:
|
| 13 |
+
from gradio_client import Client, handle_file
|
| 14 |
+
source = img_path if (img_path and os.path.exists(img_path)) else img_url
|
| 15 |
+
if not source:
|
| 16 |
+
return "a premium product"
|
| 17 |
+
client = Client("vikhyatk/moondream2", verbose=False)
|
| 18 |
+
result = client.predict(
|
| 19 |
+
handle_file(source),
|
| 20 |
+
"Describe this product briefly and concisely. What is it?",
|
| 21 |
+
api_name="/answer_question",
|
| 22 |
+
)
|
| 23 |
+
return str(result).strip() if result else "a premium product"
|
| 24 |
+
except Exception:
|
| 25 |
+
return "a premium product"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def craft_marketing_prompt(caption: str) -> str:
|
| 29 |
+
if not caption:
|
| 30 |
+
caption = "a premium product"
|
| 31 |
+
caption = caption.strip().rstrip(".")
|
| 32 |
+
styles = [
|
| 33 |
+
(
|
| 34 |
+
f"Professional product advertisement photograph of {caption}, "
|
| 35 |
+
"studio lighting, clean white background, commercial photography, "
|
| 36 |
+
"ultra-sharp, 8K quality"
|
| 37 |
+
),
|
| 38 |
+
(
|
| 39 |
+
f"Cinematic product shot of {caption}, dramatic lighting, "
|
| 40 |
+
"aspirational lifestyle context, premium brand aesthetic, "
|
| 41 |
+
"shot on Hasselblad, magazine cover quality"
|
| 42 |
+
),
|
| 43 |
+
(
|
| 44 |
+
f"Bold marketing campaign visual of {caption}, vibrant colors, "
|
| 45 |
+
"dynamic composition, modern editorial style, "
|
| 46 |
+
"award-winning commercial photography"
|
| 47 |
+
),
|
| 48 |
+
]
|
| 49 |
+
return random.choice(styles)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
demo = gr.Workflow(bind=[describe_product, craft_marketing_prompt])
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
demo.launch()
|
| 56 |
+
|
workflow.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"schema_version":"2","name":"Marketing Image Creator","runtime":{"default":"client"},"references":[{"label":"Text","inputs":[{"id":"in","label":"Text","type":"text"}],"outputs":[{"id":"out","label":"Text","type":"text"}],"width":220,"height":163,"asset_type":"text","role":"reference","id":"1539a1e9-4906-4008-b345-e6d05bb69b22","x":740,"y":80,"data":{"in":null}},{"label":"Image","inputs":[{"id":"in","label":"Image","type":"image"}],"outputs":[{"id":"out","label":"Image","type":"image"}],"width":220,"height":124,"asset_type":"image","role":"reference","id":"13e92b22-7173-416c-81c6-1ca097a2a299","x":80,"y":80,"data":{}}],"operators":[{"id":"n_flux","label":"Generate Image","inputs":[{"id":"in","label":"Prompt","type":"text","required":true}],"outputs":[{"id":"out","label":"Image","type":"image"}],"data":{"out":97500097},"x":1040,"y":80,"width":220,"height":124,"role":"operator","kind":"space","source":"hf://spaces/multimodalart/FLUX.1-merged","space_id":"multimodalart/FLUX.1-merged","runtime":"client","endpoints":[{"name":"/infer","inputs":[{"id":"in_0","label":"Prompt","type":"text","required":true},{"id":"in_1","label":"Seed","type":"number","required":false},{"id":"in_2","label":"Randomize seed","type":"boolean","required":false},{"id":"in_3","label":"Width","type":"number","required":false},{"id":"in_4","label":"Height","type":"number","required":false},{"id":"in_5","label":"Guidance Scale","type":"number","required":false},{"id":"in_6","label":"Number of inference steps","type":"number","required":false}],"outputs":[{"id":"out_0","label":"Result","type":"image","output_index":0},{"id":"out_1","label":"Seed","type":"number","output_index":1}]}]},{"label":"Image To Prompt","inputs":[{"id":"in_0","label":"Input Image","type":"image","required":true}],"outputs":[{"id":"out_0","label":"Output Prompt","type":"text","output_index":0}],"width":280,"height":124,"kind":"space","space_id":"ovi054/image-to-prompt","endpoint":"/predict","endpoints":[{"name":"/predict","inputs":[{"id":"in_0","label":"Input Image","type":"image","required":true}],"outputs":[{"id":"out_0","label":"Output Prompt","type":"text","output_index":0}]}],"pipeline_tag":"Image Captioning","role":"operator","id":"897592dc-17b5-473b-9e89-4ebdae4073d6","x":380,"y":80,"data":{}}],"subjects":[{"id":"n_output","label":"Marketing Image","inputs":[{"id":"in","label":"Image","type":"image"}],"outputs":[{"id":"out","label":"Image","type":"image"}],"data":{"in":null},"x":1340,"y":80,"width":220,"height":107,"role":"subject","asset_type":"image"}],"edges":[{"id":"e4","from_node_id":"n_flux","from_port_id":"out","to_node_id":"n_output","to_port_id":"in","type":"image"},{"from_node_id":"1539a1e9-4906-4008-b345-e6d05bb69b22","from_port_id":"out","to_node_id":"n_flux","to_port_id":"in","type":"text","id":"b44e83fe-23b1-4dcc-83d3-55b3481721bc"},{"from_node_id":"13e92b22-7173-416c-81c6-1ca097a2a299","from_port_id":"out","to_node_id":"897592dc-17b5-473b-9e89-4ebdae4073d6","to_port_id":"in_0","type":"image","id":"22796709-ff7d-4250-92c0-2d541f9e6a99"},{"from_node_id":"897592dc-17b5-473b-9e89-4ebdae4073d6","from_port_id":"out_0","to_node_id":"1539a1e9-4906-4008-b345-e6d05bb69b22","to_port_id":"in","type":"text","id":"96dab823-0f2c-4356-98c4-aa82feca5e0a"}],"view":{"default":"canvas"}}
|