Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,106 +1,33 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
print(f'Route: /eval/{expression}')
|
28 |
-
|
29 |
-
# You can do some processing here before rendering the template.
|
30 |
-
result = eval(expression)
|
31 |
-
print(f"\tResult: {result}")
|
32 |
-
|
33 |
-
return flask.render_template('evaluate-expression.html', expression=expression, result=result)
|
34 |
-
|
35 |
-
@app.route('/show/circle')
|
36 |
-
def show_circle():
|
37 |
-
img = draw.circle(width=500, height=500)
|
38 |
-
image = Convert.cv_to_base64(img)
|
39 |
-
return flask.render_template('show-image.html', image=image, imageLabel='Circle')
|
40 |
-
|
41 |
-
@app.route('/show/shapes')
|
42 |
-
def show_shapes():
|
43 |
-
return flask.render_template('show-shapes.html')
|
44 |
-
|
45 |
-
@app.route('/draw', methods=['GET'])
|
46 |
-
def draw_target():
|
47 |
-
"""
|
48 |
-
Try testing with:
|
49 |
-
curl -X GET "localhost:5000/draw?target=blank"
|
50 |
-
curl -X GET "localhost:5000/draw?target=circle"
|
51 |
-
curl -X GET "localhost:5000/draw?target=rectangle"
|
52 |
-
"""
|
53 |
-
# TODO: Call this from javascript for toggling between images.
|
54 |
-
target = flask.request.args.get('target', default='blank', type=str)
|
55 |
-
width = flask.request.args.get('width', default=500, type=int)
|
56 |
-
height = flask.request.args.get('height', default=500, type=int)
|
57 |
-
|
58 |
-
if target == 'blank':
|
59 |
-
img = draw.blank(width=width, height=height)
|
60 |
-
elif target == 'circle':
|
61 |
-
img = draw.circle(width=width, height=height)
|
62 |
-
elif target == 'rectangle':
|
63 |
-
img = draw.rectangle(width=width, height=height)
|
64 |
-
else:
|
65 |
-
raise ValueError(f'Unsupported target: {target}')
|
66 |
-
|
67 |
-
image = Convert.cv_to_base64(img)
|
68 |
-
return flask.jsonify(
|
69 |
-
isError=False,
|
70 |
-
message='Success',
|
71 |
-
statusCode=200,
|
72 |
-
data=image
|
73 |
)
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
"""
|
78 |
-
Try testing with:
|
79 |
-
curl -X GET "localhost:5000/echo?a=hello&b=world"
|
80 |
-
curl -X POST "localhost:5000/echo?a=hello&b=world"
|
81 |
-
"""
|
82 |
-
msg = 'Echo:'
|
83 |
-
for key, val in flask.request.args.to_dict().items():
|
84 |
-
msg += f'\n\t{key}={val}'
|
85 |
-
if flask.request.method == 'GET':
|
86 |
-
return flask.jsonify(
|
87 |
-
isError=False,
|
88 |
-
message='Success',
|
89 |
-
statusCode=200,
|
90 |
-
data=msg
|
91 |
-
)
|
92 |
-
else:
|
93 |
-
print(msg)
|
94 |
-
return flask.jsonify(
|
95 |
-
isError=False,
|
96 |
-
message='Success',
|
97 |
-
statusCode=200,
|
98 |
-
# data=msg
|
99 |
-
)
|
100 |
-
|
101 |
-
@app.route('/debug/scrolling')
|
102 |
-
def debug_scrolling():
|
103 |
-
return flask.render_template('scroll_debug.html')
|
104 |
|
105 |
if __name__ == '__main__':
|
106 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
from gradio_client import Client
|
3 |
+
|
4 |
+
app = Flask(__name__)
|
5 |
+
|
6 |
+
@app.route('/', methods=['GET'])
|
7 |
+
def get_prediction():
|
8 |
+
|
9 |
+
# Extract data for prediction
|
10 |
+
prompt = request.args.get("prompt")
|
11 |
+
negative_prompt = request.args.get("negative_prompt")
|
12 |
+
width = int(request.args.get("width"))
|
13 |
+
height = int(request.args.get("height"))
|
14 |
+
|
15 |
+
# Make prediction using Gradio Client
|
16 |
+
client = Client("https://ddosxd-realvisxl.hf.space/--replicas/flm7z/")
|
17 |
+
result = client.predict(
|
18 |
+
prompt,
|
19 |
+
negative_prompt,
|
20 |
+
True,
|
21 |
+
0,
|
22 |
+
width,
|
23 |
+
height,
|
24 |
+
7,
|
25 |
+
True,
|
26 |
+
api_name="/run"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
)
|
28 |
|
29 |
+
# Return the result as JSON response
|
30 |
+
return jsonify(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
if __name__ == '__main__':
|
33 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|