Spaces:
Runtime error
Runtime error
Commit
·
073d257
1
Parent(s):
6d87ed3
Changes
Browse files
app.py
CHANGED
|
@@ -6,7 +6,8 @@ import os
|
|
| 6 |
from torch import autocast
|
| 7 |
from diffusers import StableDiffusionPipeline, DDIMScheduler, DiffusionPipeline
|
| 8 |
import streamlit as st
|
| 9 |
-
|
|
|
|
| 10 |
from huggingface_hub import login
|
| 11 |
|
| 12 |
# HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
@@ -14,11 +15,11 @@ from huggingface_hub import login
|
|
| 14 |
login(token='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')
|
| 15 |
|
| 16 |
|
| 17 |
-
pipe = StableDiffusionPipeline.from_pretrained("Divyanshu04/Finetuned-model", safety_checker=None, torch_dtype=torch.
|
| 18 |
|
| 19 |
-
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
| 20 |
# pipe.enable_xformers_memory_efficient_attention() #if gpu is available
|
| 21 |
-
g_cuda = None
|
| 22 |
|
| 23 |
FILE = Path(__file__).resolve()
|
| 24 |
ROOT = FILE.parents[0] # YOLOv5 root directory
|
|
@@ -27,6 +28,16 @@ if str(ROOT) not in sys.path:
|
|
| 27 |
ROOT = Path(os.path.relpath(ROOT, Path.cwd()))
|
| 28 |
|
| 29 |
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
# @app.route("/", methods=["POST"])
|
|
@@ -41,29 +52,34 @@ def generate():
|
|
| 41 |
|
| 42 |
if Submit:
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
st.image(
|
| 67 |
|
| 68 |
else:
|
| 69 |
st.write('<Enter parameters to generate image>')
|
|
|
|
| 6 |
from torch import autocast
|
| 7 |
from diffusers import StableDiffusionPipeline, DDIMScheduler, DiffusionPipeline
|
| 8 |
import streamlit as st
|
| 9 |
+
import io
|
| 10 |
+
from PIL import Image
|
| 11 |
from huggingface_hub import login
|
| 12 |
|
| 13 |
# HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
|
|
| 15 |
login(token='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')
|
| 16 |
|
| 17 |
|
| 18 |
+
# pipe = StableDiffusionPipeline.from_pretrained("Divyanshu04/Finetuned-model", safety_checker=None, torch_dtype=torch.float16).to("cpu")
|
| 19 |
|
| 20 |
+
# pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
| 21 |
# pipe.enable_xformers_memory_efficient_attention() #if gpu is available
|
| 22 |
+
# g_cuda = None
|
| 23 |
|
| 24 |
FILE = Path(__file__).resolve()
|
| 25 |
ROOT = FILE.parents[0] # YOLOv5 root directory
|
|
|
|
| 28 |
ROOT = Path(os.path.relpath(ROOT, Path.cwd()))
|
| 29 |
|
| 30 |
app = Flask(__name__)
|
| 31 |
+
|
| 32 |
+
import requests
|
| 33 |
+
|
| 34 |
+
API_URL = "https://api-inference.huggingface.co/models/Divyanshu04/Finetuned-model"
|
| 35 |
+
headers = {"Authorization": "Bearer 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"}
|
| 36 |
+
|
| 37 |
+
def query(payload):
|
| 38 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 39 |
+
return response.content
|
| 40 |
+
|
| 41 |
|
| 42 |
|
| 43 |
# @app.route("/", methods=["POST"])
|
|
|
|
| 52 |
|
| 53 |
if Submit:
|
| 54 |
|
| 55 |
+
image_bytes = query({"inputs": prompt,})
|
| 56 |
+
# You can access the image with PIL.Image for example
|
| 57 |
+
|
| 58 |
+
image = Image.open(io.BytesIO(image_bytes))
|
| 59 |
+
|
| 60 |
+
# guidance_scale = 7.5
|
| 61 |
+
# num_inference_steps = 24
|
| 62 |
+
# height = 512
|
| 63 |
+
# width = 512
|
| 64 |
+
|
| 65 |
+
# g_cuda = torch.Generator(device='cpu')
|
| 66 |
+
# seed = 52362
|
| 67 |
+
# g_cuda.manual_seed(seed)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# with autocast("cpu"), torch.inference_mode():
|
| 71 |
+
# images = pipe(
|
| 72 |
+
# prompt,
|
| 73 |
+
# height=height,
|
| 74 |
+
# width=width,
|
| 75 |
+
# negative_prompt=negative_prompt,
|
| 76 |
+
# num_images_per_prompt=num_samples,
|
| 77 |
+
# num_inference_steps=num_inference_steps,
|
| 78 |
+
# guidance_scale=guidance_scale,
|
| 79 |
+
# generator=g_cuda
|
| 80 |
+
# ).images
|
| 81 |
|
| 82 |
+
st.image(image)
|
| 83 |
|
| 84 |
else:
|
| 85 |
st.write('<Enter parameters to generate image>')
|