shichen commited on
Commit
1d17a15
1 Parent(s): 8370647
Files changed (2) hide show
  1. app.py +37 -10
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,19 +1,46 @@
 
1
  import gradio as gr
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- def greet(name):
5
- return "Hello " + name + "!"
6
-
7
-
8
  with gr.Blocks() as demo:
9
-
10
  with gr.Row():
11
  with gr.Column(scale=1):
12
- text1 = gr.Textbox(label="API Key")
13
- name = gr.Textbox(label="Prompt")
14
- greet_btn = gr.Button("Greet")
 
 
 
 
15
  with gr.Column(scale=1):
16
  output = gr.Image()
17
- greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
 
 
 
18
 
19
- demo.launch()
 
1
+ import requests
2
  import gradio as gr
3
 
4
+ # 修改 greet 函数以处理图像生成
5
+ def generate_image(api_key, prompt, aspect_ratio, model, negative_prompt, seed):
6
+ response = requests.post(
7
+ "https://api.stability.ai/v2beta/stable-image/generate/sd3",
8
+ headers={
9
+ "authorization": f"Bearer {api_key}",
10
+ "accept": "image/*"
11
+ },
12
+ files={"none": ''},
13
+ data={
14
+ "prompt": prompt,
15
+ "aspect_ratio": aspect_ratio,
16
+ "model": model,
17
+ "negative_prompt": negative_prompt,
18
+ "seed": seed,
19
+ "output_format": "jpeg",
20
+ },
21
+ )
22
+
23
+ if response.status_code == 200:
24
+ return response.content
25
+ else:
26
+ raise Exception(str(response.json()))
27
 
28
+ # 构建 Gradio 界面
 
 
 
29
  with gr.Blocks() as demo:
 
30
  with gr.Row():
31
  with gr.Column(scale=1):
32
+ api_key = gr.Textbox(label="API Key")
33
+ prompt = gr.Textbox(label="Prompt", placeholder="What you wish to see in the output image.")
34
+ aspect_ratio = gr.Dropdown(label="Aspect Ratio", choices=["16:9", "1:1", "21:9", "2:3", "3:2", "4:5", "5:4", "9:16", "9:21"], value="1:1")
35
+ model = gr.Dropdown(label="Model", choices=["sd3", "sd3-turbo"], value="sd3")
36
+ negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="Describe what you do not wish to see.")
37
+ seed = gr.Number(label="Seed", value=0, minimum=0, maximum=4294967294, step=1)
38
+ generate_btn = gr.Button("Generate Image")
39
  with gr.Column(scale=1):
40
  output = gr.Image()
41
+
42
+ generate_btn.click(fn=generate_image,
43
+ inputs=[api_key, prompt, aspect_ratio, model, negative_prompt, seed],
44
+ outputs=output)
45
 
46
+ demo.launch(server_port=7588)
requirements.txt CHANGED
@@ -1 +1,2 @@
1
- gradio
 
 
1
+ gradio
2
+ requests