Spaces:
Sleeping
Sleeping
Commit
•
0112c3e
1
Parent(s):
4430182
Update flask_app.py
Browse files- flask_app.py +45 -2
flask_app.py
CHANGED
@@ -1,10 +1,11 @@
|
|
1 |
|
2 |
import os
|
3 |
-
from flask import Flask, flash, request, redirect, url_for, session
|
4 |
from flask_session import Session
|
5 |
from werkzeug.utils import secure_filename
|
6 |
from example_inference import example_inference
|
7 |
from flask import send_from_directory
|
|
|
8 |
import base64
|
9 |
|
10 |
UPLOAD_FOLDER = 'images'
|
@@ -16,7 +17,49 @@ app.config["SESSION_TYPE"] = "filesystem"
|
|
16 |
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
17 |
|
18 |
Session(app)
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
def allowed_file(filename):
|
21 |
return '.' in filename and \
|
22 |
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
|
|
1 |
|
2 |
import os
|
3 |
+
from flask import Flask, flash, request, redirect, url_for, session, jsonify
|
4 |
from flask_session import Session
|
5 |
from werkzeug.utils import secure_filename
|
6 |
from example_inference import example_inference
|
7 |
from flask import send_from_directory
|
8 |
+
from gradio_client import Client
|
9 |
import base64
|
10 |
|
11 |
UPLOAD_FOLDER = 'images'
|
|
|
17 |
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
18 |
|
19 |
Session(app)
|
20 |
+
|
21 |
+
client = Client("stabilityai/stable-diffusion-3-medium")
|
22 |
+
|
23 |
+
|
24 |
+
def generate_logo(prompt):
|
25 |
+
"""Generates a logo using the provided prompt."""
|
26 |
+
|
27 |
+
result = client.predict(
|
28 |
+
prompt=prompt,
|
29 |
+
negative_prompt="",
|
30 |
+
seed=0,
|
31 |
+
randomize_seed=True,
|
32 |
+
width=1024,
|
33 |
+
height=1024,
|
34 |
+
guidance_scale=7,
|
35 |
+
num_inference_steps=50,
|
36 |
+
api_name="/infer",
|
37 |
+
)
|
38 |
+
return result
|
39 |
+
|
40 |
+
|
41 |
+
@app.route('/logo', methods=['POST'])
|
42 |
+
def generate_response():
|
43 |
+
try:
|
44 |
+
data = request.get_json()
|
45 |
+
|
46 |
+
if 'prompt' in data :
|
47 |
+
prompt = data['prompt']
|
48 |
+
|
49 |
+
response = generate_logo(prompt)
|
50 |
+
print(response, 'response')
|
51 |
+
fileUrl = f'https://stabilityai-stable-diffusion-3-medium.hf.space/file={response[0]}'
|
52 |
+
|
53 |
+
return jsonify(fileUrl)
|
54 |
+
|
55 |
+
else:
|
56 |
+
return jsonify({"error": "Missing required parameters"}), 400
|
57 |
+
|
58 |
+
except Exception as e:
|
59 |
+
return jsonify({"Error": str(e)}), 500
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
def allowed_file(filename):
|
64 |
return '.' in filename and \
|
65 |
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|