Update app.py
Browse files
app.py
CHANGED
@@ -5,12 +5,6 @@ from externalmod import gr_Interface_load
|
|
5 |
import asyncio
|
6 |
import os
|
7 |
from threading import RLock
|
8 |
-
from gradio_client import Client
|
9 |
-
from flask import Flask, request, jsonify, send_file
|
10 |
-
|
11 |
-
|
12 |
-
client = Client("Geek7/mdztxi2")
|
13 |
-
|
14 |
|
15 |
lock = RLock()
|
16 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
@@ -55,31 +49,12 @@ async def infer(model_str, prompt, seed=1, timeout=inference_timeout):
|
|
55 |
return None
|
56 |
|
57 |
# Expose Gradio API
|
58 |
-
|
59 |
result = asyncio.run(infer(model_str, prompt, seed))
|
60 |
if result:
|
61 |
return result # Path to generated image
|
62 |
return None
|
63 |
|
64 |
-
@app.route('/predict2', methods=['POST'])
|
65 |
-
def async_infer_api():
|
66 |
-
data = request.get_json()
|
67 |
-
model_str = data['model_str']
|
68 |
-
prompt = data['prompt']
|
69 |
-
seed = data.get('seed', 1) # Default seed value to 1 if not provided
|
70 |
-
|
71 |
-
try:
|
72 |
-
# Run the asynchronous inference function
|
73 |
-
result_path = asyncio.run(async_infer(model_str, prompt, seed))
|
74 |
-
if result_path:
|
75 |
-
# Use send_file to return the generated image
|
76 |
-
return send_file(result_path, mimetype='image/png') # Adjust mimetype as needed
|
77 |
-
else:
|
78 |
-
return jsonify({"error": "Image generation failed."}), 500
|
79 |
-
except Exception as e:
|
80 |
-
return jsonify({"error": str(e)}), 500
|
81 |
-
|
82 |
-
|
83 |
# Launch Gradio API without frontend
|
84 |
-
iface = gr.Interface(fn=
|
85 |
iface.launch(show_api=True, share=True)
|
|
|
5 |
import asyncio
|
6 |
import os
|
7 |
from threading import RLock
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
lock = RLock()
|
10 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
|
49 |
return None
|
50 |
|
51 |
# Expose Gradio API
|
52 |
+
def generate_api(model_str, prompt, seed=1):
|
53 |
result = asyncio.run(infer(model_str, prompt, seed))
|
54 |
if result:
|
55 |
return result # Path to generated image
|
56 |
return None
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
# Launch Gradio API without frontend
|
59 |
+
iface = gr.Interface(fn=generate_api, inputs=["text", "text", "number"], outputs="file")
|
60 |
iface.launch(show_api=True, share=True)
|