JV A commited on
Commit
da1b766
·
1 Parent(s): fedcf0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -95
app.py CHANGED
@@ -1,107 +1,91 @@
1
  import gradio as gr
2
  import requests
 
 
 
3
 
4
  def generate_image(prompt):
5
- apiUrl = 'https://apiv2.makeai.run/v2/txt2img' # Replace with your API URL
6
- data = {
7
- "mode": "url",
8
- "model": "AOM3A1B_orangemixs.safetensors",
9
- "tiling": false,
10
- "batch_size": 1,
11
- "prompt": prompt,
12
- "negative_prompt": "worst quality, lowres",
13
- "seed": 1234,
14
- "scheduler": "Euler a",
15
- "n_iter": 1,
16
- "steps": 30,
17
- "cfg": 11.0,
18
- "offset_noise": 0.0,
19
- "width": 1024,
20
- "height": 1024,
21
- "clip_skip": 1,
22
- "loras": [
23
- {
24
- "name": "",
25
- "strength": 1.0
26
- }
27
- ],
28
- "embeddings": [
29
- {
30
- "name": "",
31
- "strength": 1.0
32
- }
33
- ],
34
- "vae": "vae-ft-mse-840000-ema-pruned.ckpt",
35
- "restore_faces": false,
36
- "fr_model": "CodeFormer",
37
- "codeformer_weight": 0.5,
38
- "enable_hr": false,
39
- "denoising_strength": 0.75,
40
- "hr_scale": 2,
41
- "hr_upscale": "None",
42
- "img2img_ref_img_type": "piece",
43
- "img2img_resize_mode": 0,
44
- "img2img_denoising_strength": 0.75,
45
- "controlnet_enabled": false,
46
- "controlnet_ref_img_type": "piece",
47
- "controlnet_guessmode": false,
48
- "controlnet_module": "canny",
49
- "controlnet_model": "control_v11p_sd15_softedge",
50
- "controlnet_weight": 1,
51
- "controlnet_guidance_start": 0,
52
- "controlnet_guidance_end": 1,
53
- "controlnet_ref_img_url": "",
54
- "controlnet_mask": [],
55
- "controlnet_resize_mode": "Scale to Fit (Inner Fit)",
56
- "controlnet_lowvram": false,
57
- "controlnet_processor_res": 512,
58
- "controlnet_threshold_a": 100,
59
- "controlnet_threshold_b": 200
60
- }
61
- headers = {
62
- 'Content-Type': 'application/json',
63
- 'token': '514f7ecde6a5434dbab5c6579311ad82' # Replace with your API token
64
- }
65
- response = requests.post(apiUrl, json=data, headers=headers)
66
- responseData = response.json()
67
- if responseData and responseData['results'] and responseData['results'][0]:
68
- return responseData['results'][0]
69
- else:
70
- return "No image generated"
71
 
72
- # Uncomment the following lines if you want to use the control image component
73
- # def generate_image(prompt, control_image):
74
- # apiUrl = 'https://apiv2.makeai.run/v2/txt2img' # Replace with your API URL
75
- # data = {
76
- # ...
77
- # "controlnet_ref_img_url": control_image,
78
- # ...
79
- # }
80
- # headers = {
81
- # ...
82
- # }
83
- # response = requests.post(apiUrl, json=data, headers=headers)
84
- # responseData = response.json()
85
- # if responseData and responseData['results'] and responseData['results'][0]:
86
- # return responseData['results'][0]
87
- # else:
88
- # return "No image generated"
89
 
90
- title = gr.outputs.Textbox(label="Freedom Demonstration")
91
- prompt = gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here", label="Prompt")
92
- image = gr.outputs.Image(label="Generated Image")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
- # Uncomment the following line if you want to use the control image component
95
- # control_image = gr.inputs.Image(label="Control Image (optional)")
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  iface = gr.Interface(
98
- fn=generate_image,
99
- inputs=[prompt], # Add control_image to the list if you want to use it
100
- outputs=[title, image],
101
- title="Freedom Demonstration",
102
- description="This is a Gradio app that uses an API to generate images based on text prompts.",
103
- live=False,
104
- layout="vertical"
105
  )
106
 
 
107
  iface.launch()
 
1
  import gradio as gr
2
  import requests
3
+ import json
4
+ import PIL.Image
5
+ from io import BytesIO
6
 
7
  def generate_image(prompt):
8
+ # Define the API endpoint
9
+ apiUrl = "https://apiv2.makeai.run/v2/txt2img"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ # Define the request headers
12
+ headers = {
13
+ "Content-Type": "application/json",
14
+ "token": "514f7ecde6a5434dbab5c6579311ad82"
15
+ }
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ # Define the request body
18
+ body = {
19
+ "mode": "url",
20
+ "model": "AOM3A1B_orangemixs.safetensors",
21
+ "tiling": False,
22
+ "batch_size": 1,
23
+ "prompt": prompt,
24
+ "negative_prompt": "worst quality, lowres",
25
+ "seed": 1234,
26
+ "scheduler": "Euler a",
27
+ "n_iter": 1,
28
+ "steps": 25,
29
+ "cfg": 11.0,
30
+ "offset_noise": 0.0,
31
+ "width": 512,
32
+ "height": 512,
33
+ "clip_skip": 1,
34
+ "loras": [{"name": "", "strength": 1.0}],
35
+ "embeddings": [{"name": "", "strength": 1.0}],
36
+ "vae": "vae-ft-mse-840000-ema-pruned.ckpt",
37
+ "restore_faces": False,
38
+ "fr_model": "CodeFormer",
39
+ "codeformer_weight": 0.5,
40
+ "enable_hr": False,
41
+ "denoising_strength": 0.75,
42
+ "hr_scale": 2,
43
+ "hr_upscale": "None",
44
+ "img2img_ref_img_type": "piece",
45
+ "img2img_resize_mode": 0,
46
+ "img2img_denoising_strength": 0.75,
47
+ "controlnet_enabled": False,
48
+ "controlnet_ref_img_type": "piece",
49
+ "controlnet_guessmode": False,
50
+ "controlnet_module": "canny",
51
+ "controlnet_model": "control_v11p_sd15_softedge",
52
+ "controlnet_weight": 1,
53
+ "controlnet_guidance_start": 0,
54
+ "controlnet_guidance_end": 1,
55
+ "controlnet_ref_img_url": "https://upload.wikimedia.org/wikipedia/commons/d/d1/Image_not_available.png",
56
+ "controlnet_mask": [],
57
+ "controlnet_resize_mode": "Scale to Fit (Inner Fit)",
58
+ "controlnet_lowvram": False,
59
+ "controlnet_processor_res": 512,
60
+ "controlnet_threshold_a": 100,
61
+ "controlnet_threshold_b": 200
62
+ }
63
 
64
+ # Send the request
65
+ response = requests.post(apiUrl, headers=headers, data=json.dumps(body))
66
 
67
+ # Check the response status
68
+ if response.status_code == 200:
69
+ # Get the image URL from the response
70
+ image_url = json.loads(response.text)['results'][0]
71
+
72
+ # Get the image from the URL
73
+ image_response = requests.get(image_url)
74
+ image = PIL.Image.open(BytesIO(image_response.content))
75
+
76
+ return image
77
+ else:
78
+ raise Exception("API request failed with status code " + str(response.status_code))
79
+
80
+ # Define the Gradio interface
81
  iface = gr.Interface(
82
+ fn=generate_image,
83
+ inputs="text",
84
+ outputs="image",
85
+ title="Freedom Demonstration",
86
+ description="Enter a prompt and generate an image.",
87
+ allow_flagging=False
 
88
  )
89
 
90
+ # Launch the app
91
  iface.launch()