hannabaker commited on
Commit
d6e0616
·
verified ·
1 Parent(s): 1a31f1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -32
app.py CHANGED
@@ -97,43 +97,75 @@ def upload_image(url):
97
  print(f"Failed to upload: {url}")
98
  return None
99
 
100
- @app.post("/generate-image")
101
- async def generate_image(request: ImageRequest):
102
- print("Image Generation Request", request)
103
- try:
104
- runware = Runware(api_key=RUNWARE_API_KEY)
105
- await runware.connect()
106
 
107
- request_image = IImageInference(
108
- positivePrompt=request.prompt,
109
- model=request.model,
110
- numberResults=request.number_results,
111
- height=request.height,
112
- width=request.width,
113
- )
114
 
115
- images = await runware.imageInference(requestImage=request_image)
116
- image_urls = [image.imageURL for image in images]
117
- print("Generated Images: ", image_urls)
118
- # imgbb_urls = []
119
 
120
- # with ThreadPoolExecutor(max_workers=10) as executor:
121
- # future_to_url = {executor.submit(upload_image, url): url for url in image_urls}
122
- # for future in as_completed(future_to_url):
123
- # url = future_to_url[future]
124
- # try:
125
- # imgbb_url = future.result()
126
- # if imgbb_url:
127
- # imgbb_urls.append(imgbb_url)
128
- # except Exception as exc:
129
- # print(f"{url} generated an exception: {exc}")
130
 
131
- batch_id = insert_batch(request.prompt, request.width, request.height, request.model, image_urls)
132
 
133
- response = {"batch": {"id": batch_id, "prompt": request.prompt, "width": request.width, "height": request.height, "model": request.model, "images": [{"url": url} for url in image_urls]}}
134
- return response
135
- except Exception as e:
136
- raise HTTPException(status_code=500, detail=f"Failed to generate image: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
  @app.get("/get-batches")
139
  async def get_batches():
 
97
  print(f"Failed to upload: {url}")
98
  return None
99
 
100
+ # @app.post("/generate-image")
101
+ # async def generate_image(request: ImageRequest):
102
+ # print("Image Generation Request", request)
103
+ # try:
104
+ # runware = Runware(api_key=RUNWARE_API_KEY)
105
+ # await runware.connect()
106
 
107
+ # request_image = IImageInference(
108
+ # positivePrompt=request.prompt,
109
+ # model=request.model,
110
+ # numberResults=request.number_results,
111
+ # height=request.height,
112
+ # width=request.width,
113
+ # )
114
 
115
+ # images = await runware.imageInference(requestImage=request_image)
116
+ # image_urls = [image.imageURL for image in images]
117
+ # print("Generated Images: ", image_urls)
118
+ # # imgbb_urls = []
119
 
120
+ # # with ThreadPoolExecutor(max_workers=10) as executor:
121
+ # # future_to_url = {executor.submit(upload_image, url): url for url in image_urls}
122
+ # # for future in as_completed(future_to_url):
123
+ # # url = future_to_url[future]
124
+ # # try:
125
+ # # imgbb_url = future.result()
126
+ # # if imgbb_url:
127
+ # # imgbb_urls.append(imgbb_url)
128
+ # # except Exception as exc:
129
+ # # print(f"{url} generated an exception: {exc}")
130
 
131
+ # batch_id = insert_batch(request.prompt, request.width, request.height, request.model, image_urls)
132
 
133
+ # response = {"batch": {"id": batch_id, "prompt": request.prompt, "width": request.width, "height": request.height, "model": request.model, "images": [{"url": url} for url in image_urls]}}
134
+ # return response
135
+ # except Exception as e:
136
+ # raise HTTPException(status_code=500, detail=f"Failed to generate image: {str(e)}")
137
+
138
+ @app.post("/generate-image")
139
+ async def generate_image(request: ImageRequest):
140
+ print("Image Generation Request", request)
141
+ try:
142
+ runware = Runware(api_key=RUNWARE_API_KEY)
143
+ await runware.connect()
144
+
145
+ request_image = IImageInference(
146
+ positivePrompt=request.prompt,
147
+ model=request.model,
148
+ numberResults=request.number_results,
149
+ height=request.height,
150
+ width=request.width,
151
+ )
152
+
153
+ images = await runware.imageInference(requestImage=request_image)
154
+ image_urls = [image.imageURL for image in images]
155
+ print("Generated Images: ", image_urls)
156
+
157
+ response = {
158
+ "batch": {
159
+ "prompt": request.prompt,
160
+ "width": request.width,
161
+ "height": request.height,
162
+ "model": request.model,
163
+ "images": [{"url": url} for url in image_urls]
164
+ }
165
+ }
166
+ return response
167
+ except Exception as e:
168
+ raise HTTPException(status_code=500, detail=f"Failed to generate image: {str(e)}")
169
 
170
  @app.get("/get-batches")
171
  async def get_batches():