Spaces:
Paused
Paused
Commit ·
866f513
1
Parent(s): e926682
Update run.py
Browse files
run.py
CHANGED
|
@@ -6,33 +6,34 @@ import aiohttp
|
|
| 6 |
app = Flask(__name__)
|
| 7 |
|
| 8 |
async def generate_image_async(prompt, style, ratio):
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
| 23 |
-
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
| 36 |
|
| 37 |
@app.route('/')
|
| 38 |
def index():
|
|
@@ -67,3 +68,4 @@ async def api_generate_image():
|
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
| 69 |
app.run(host="0.0.0.0", port=7860)
|
|
|
|
|
|
| 6 |
app = Flask(__name__)
|
| 7 |
|
| 8 |
async def generate_image_async(prompt, style, ratio):
|
| 9 |
+
async with aiohttp.ClientSession() as session:
|
| 10 |
+
imagine = AsyncImagine(session=session)
|
| 11 |
|
| 12 |
+
try:
|
| 13 |
+
img_data = await imagine.sdprem(
|
| 14 |
+
prompt=prompt,
|
| 15 |
+
style=Style[style],
|
| 16 |
+
ratio=Ratio[ratio]
|
| 17 |
+
)
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"An error occurred while generating the image: {e}"
|
| 20 |
|
| 21 |
+
if img_data is None:
|
| 22 |
+
return "An error occurred while generating the image."
|
| 23 |
|
| 24 |
+
img_data = await imagine.upscale(image=img_data)
|
| 25 |
|
| 26 |
+
if img_data is None:
|
| 27 |
+
return "An error occurred while upscaling the image."
|
| 28 |
|
| 29 |
+
try:
|
| 30 |
+
image_path = os.path.join(app.root_path, "static", "example.jpeg")
|
| 31 |
+
with open(image_path, mode="wb") as img_file:
|
| 32 |
+
img_file.write(img_data)
|
| 33 |
+
except Exception as e:
|
| 34 |
+
return f"An error occurred while writing the image to file: {e}"
|
| 35 |
|
| 36 |
+
return image_path
|
| 37 |
|
| 38 |
@app.route('/')
|
| 39 |
def index():
|
|
|
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
| 70 |
app.run(host="0.0.0.0", port=7860)
|
| 71 |
+
|