ka1kuk commited on
Commit
0250d76
1 Parent(s): 30a6a8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -1,10 +1,19 @@
1
- from flask import Flask, request
2
  from diffusers import StableDiffusionPipeline
3
  import torch
4
- import os
 
5
 
6
  app = Flask(__name__)
7
 
 
 
 
 
 
 
 
 
8
 
9
  model_id = "runwayml/stable-diffusion-v1-5"
10
  pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
@@ -23,6 +32,3 @@ def generate_image():
23
  image_data = image.tobytes().hex()
24
 
25
  return {'image_data': image_data}
26
-
27
- if __name__ == '__main__':
28
- app.run(host='0.0.0.0', port=5000)
 
1
+ from flask import request
2
  from diffusers import StableDiffusionPipeline
3
  import torch
4
+ from fastapi import FastAPI, Response
5
+ from fastapi.middleware.cors import CORSMiddleware
6
 
7
  app = Flask(__name__)
8
 
9
+ app.add_middleware( # add the middleware
10
+ CORSMiddleware,
11
+ allow_credentials=True, # allow credentials
12
+ allow_origins=["*"], # allow all origins
13
+ allow_methods=["*"], # allow all methods
14
+ allow_headers=["*"], # allow all headers
15
+ )
16
+
17
 
18
  model_id = "runwayml/stable-diffusion-v1-5"
19
  pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
 
32
  image_data = image.tobytes().hex()
33
 
34
  return {'image_data': image_data}