Update app.py
Browse files
app.py
CHANGED
@@ -64,20 +64,25 @@ def generate_api(model_str, prompt, seed=1):
|
|
64 |
return None
|
65 |
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
return result_path
|
74 |
-
if result_path:
|
75 |
-
# Send back the generated image file
|
76 |
-
return send_file(result_path, mimetype='image/png')
|
77 |
-
else:
|
78 |
-
return jsonify({"error": "Failed to generate image."}), 500
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
|
|
|
|
|
|
|
|
|
|
81 |
# Launch Gradio API without frontend
|
82 |
iface = gr.Interface(fn=generate_api, inputs=["text", "text", "number"], outputs="file")
|
83 |
iface.launch(show_api=True, share=True)
|
|
|
64 |
return None
|
65 |
|
66 |
|
67 |
+
def predict():
|
68 |
+
data = request.get_json()
|
69 |
+
model_str = data['model_str']
|
70 |
+
prompt = data['prompt']
|
71 |
+
seed = data.get('seed', 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
client = Client("Geek7/mdztxi2")
|
74 |
+
result_path = client.predict(
|
75 |
+
model_str=model_str,
|
76 |
+
prompt=prompt,
|
77 |
+
seed=seed,
|
78 |
+
api_name="/predict"
|
79 |
+
)
|
80 |
|
81 |
+
if result_path:
|
82 |
+
# Send back the generated image file
|
83 |
+
return send_file(result_path, mimetype='image/png')
|
84 |
+
else:
|
85 |
+
return jsonify({"error": "Failed to generate image."}), 500
|
86 |
# Launch Gradio API without frontend
|
87 |
iface = gr.Interface(fn=generate_api, inputs=["text", "text", "number"], outputs="file")
|
88 |
iface.launch(show_api=True, share=True)
|