nevreal commited on
Commit
2893884
·
verified ·
1 Parent(s): 03bdba0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import io, os
4
+ from PIL import Image
5
+
6
+
7
+
8
+ api_key = os.environ.get("HF_API_KEY")
9
+ API_URL = "https://api-inference.huggingface.co/models/multimodalart/vintage-ads-flux"
10
+ headers = {"Authorization": f"Bearer {api_key}"}
11
+
12
+ # Function to query the model
13
+ def query_image(inputs):
14
+ payload = {"inputs": inputs}
15
+ response = requests.post(API_URL, headers=headers, json=payload)
16
+ image_bytes = response.content
17
+ image = Image.open(io.BytesIO(image_bytes))
18
+ return image
19
+
20
+ # Define Gradio Blocks UI
21
+ with gr.Blocks() as demo:
22
+ gr.Markdown("# Vintage Ads Image Generator")
23
+
24
+ with gr.Row():
25
+ with gr.Column():
26
+ prompt = gr.Textbox(label="Enter your prompt", value="Astronaut riding a horse", lines=2)
27
+ submit_button = gr.Button("Generate Image")
28
+
29
+ with gr.Column():
30
+ output_image = gr.Image(label="Generated Image")
31
+
32
+ # Add examples
33
+ examples = gr.Examples(
34
+ examples=[
35
+ "a vintage ad with a woman wearing a VR headset with an apple logo and laughing, vtgads; it reads "Vision Pro" on the top and "escape the real world" in the bottom",
36
+ "a vintage ad of Twitter, the twitter bird with a speech baloon that reads "I will never be X"",
37
+ "a vintage ad of neuralink, a person with a brain computer implant, vtgads; it reads "neuralink" on the top and "if you can't defeat the AI, join it!""
38
+ ],
39
+ inputs=prompt,
40
+ )
41
+
42
+ # Link button action to function
43
+ submit_button.click(fn=query_image, inputs=prompt, outputs=output_image)
44
+
45
+ # Launch the web UI
46
+ demo.launch()