pseudotheos
commited on
Commit
•
d482ffb
1
Parent(s):
3594ff4
changed to async, hardcoded scroll logo, added negative prompts.
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import os
|
2 |
import io
|
|
|
3 |
import socket
|
4 |
import requests
|
5 |
import sys
|
@@ -113,7 +114,7 @@ def convert_to_base64(pil_image):
|
|
113 |
def inference(
|
114 |
control_image: Image.Image,
|
115 |
prompt: str,
|
116 |
-
negative_prompt
|
117 |
guidance_scale: float = 8.0,
|
118 |
controlnet_conditioning_scale: float = 1,
|
119 |
control_guidance_start: float = 1,
|
@@ -196,7 +197,8 @@ def generate_image_from_parameters(prompt, guidance_scale, controlnet_scale, con
|
|
196 |
temp_image.write(image.file.read())
|
197 |
|
198 |
# Open the uploaded image using PIL
|
199 |
-
|
|
|
200 |
|
201 |
# Call existing inference function with the provided parameters
|
202 |
generated_image, _, _, _ = inference(control_image, prompt, "", guidance_scale, controlnet_scale, 0, controlnet_end, upscaler_strength, seed, sampler_type)
|
@@ -260,9 +262,7 @@ async def generate_image(
|
|
260 |
logger.error("Error occurred during image generation: %s", str(e))
|
261 |
return "Failed to generate image"
|
262 |
|
263 |
-
|
264 |
-
import uvicorn
|
265 |
-
|
266 |
# Get internal IP address
|
267 |
internal_ip = socket.gethostbyname(socket.gethostname())
|
268 |
|
@@ -275,4 +275,11 @@ if __name__ == "__main__":
|
|
275 |
print(f"Internal URL: http://{internal_ip}:7860")
|
276 |
print(f"Public URL: http://{public_ip}:7860")
|
277 |
|
278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import io
|
3 |
+
import asyncio
|
4 |
import socket
|
5 |
import requests
|
6 |
import sys
|
|
|
114 |
def inference(
|
115 |
control_image: Image.Image,
|
116 |
prompt: str,
|
117 |
+
negative_prompt = "sexual content, racism, humans, faces",
|
118 |
guidance_scale: float = 8.0,
|
119 |
controlnet_conditioning_scale: float = 1,
|
120 |
control_guidance_start: float = 1,
|
|
|
197 |
temp_image.write(image.file.read())
|
198 |
|
199 |
# Open the uploaded image using PIL
|
200 |
+
control_image_path = "scrollwhite.png"
|
201 |
+
control_image = Image.open(control_image_path)
|
202 |
|
203 |
# Call existing inference function with the provided parameters
|
204 |
generated_image, _, _, _ = inference(control_image, prompt, "", guidance_scale, controlnet_scale, 0, controlnet_end, upscaler_strength, seed, sampler_type)
|
|
|
262 |
logger.error("Error occurred during image generation: %s", str(e))
|
263 |
return "Failed to generate image"
|
264 |
|
265 |
+
async def start_fastapi():
|
|
|
|
|
266 |
# Get internal IP address
|
267 |
internal_ip = socket.gethostbyname(socket.gethostname())
|
268 |
|
|
|
275 |
print(f"Internal URL: http://{internal_ip}:7860")
|
276 |
print(f"Public URL: http://{public_ip}:7860")
|
277 |
|
278 |
+
# Run FastAPI using hypercorn
|
279 |
+
config = uvicorn.Config(app="app:app", host="0.0.0.0", port=7860, reload=True)
|
280 |
+
server = uvicorn.Server(config)
|
281 |
+
await server.serve()
|
282 |
+
|
283 |
+
# Call the asynchronous function using asyncio.run()
|
284 |
+
if __name__ == "__main__":
|
285 |
+
asyncio.run(start_fastapi())
|