kumahiyo commited on
Commit
8dc81a8
1 Parent(s): 1ef45ad
Files changed (1) hide show
  1. main.py +28 -1
main.py CHANGED
@@ -1,7 +1,11 @@
 
 
 
1
  from fastapi import FastAPI
2
  from fastapi.staticfiles import StaticFiles
3
  from pydantic import BaseModel
4
  from pydantic import Field
 
5
 
6
  app = FastAPI()
7
 
@@ -20,6 +24,29 @@ def index():
20
  @app.post("/draw", response_model=ItemOut)
21
  def draw(data: Data):
22
  if data.member_secret != "" and data.member_secret == os.environ.get("MEMBER_SECRET"):
23
- return {"status": "OK", "file": "hello world!"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  else:
25
  return {"status": "SORRY! This file is member only.", "file": ""}
 
1
+ import os
2
+ import time
3
+ import sys
4
  from fastapi import FastAPI
5
  from fastapi.staticfiles import StaticFiles
6
  from pydantic import BaseModel
7
  from pydantic import Field
8
+ from diffusers import StableDiffusionPipeline
9
 
10
  app = FastAPI()
11
 
 
24
  @app.post("/draw", response_model=ItemOut)
25
  def draw(data: Data):
26
  if data.member_secret != "" and data.member_secret == os.environ.get("MEMBER_SECRET"):
27
+ print(f"Is CUDA available: {torch.cuda.is_available()}")
28
+
29
+ # prompt = '(('+data.string+')) (( photograph )), highly detailed, sharp focus, 8k, 4k, (( photorealism )), detailed, saturated, portrait, 50mm, F/2.8, 1m away, ( global illumination, studio light, volumetric light ), ((( multicolor lights )))'
30
+ prompt = '(('+data.string+')) (( photograph )), highly detailed, sharp focus, 8k, 4k, (( photorealism )), detailed, saturated, portrait, 50mm, F/2.8, 1m away, ((( multicolor lights )))'
31
+ n_prompt = 'text, blurry, art, painting, rendering, drawing, sketch, (( ugly )), (( duplicate )), ( morbid ), (( mutilated )), ( mutated ), ( deformed ), ( disfigured ), ( extra limbs ), ( malformed limbs ), ( missing arms ), ( missing legs ), ( extra arms ), ( extra legs ), ( fused fingers ), ( too many fingers ), long neck, low quality, worst quality'
32
+
33
+ # https://huggingface.co/docs/hub/spaces-sdks-docker-first-demo
34
+ # how to validation: https://qiita.com/bee2/items/75d9c0d7ba20e7a4a0e9
35
+ # https://github.com/huggingface/diffusers
36
+
37
+ model_id = 'stabilityai/stable-diffusion-2'
38
+
39
+ #pipe = StableDiffusionPipeline.from_pretrained(model_id, revision='fp16', torch_dtype=torch.float16)
40
+ pipe = StableDiffusionPipeline.from_pretrained(model_id)
41
+ #pipe = pipe.to('cuda')
42
+
43
+ image = pipe(prompt, negative_prompt=n_prompt).images[0]
44
+
45
+ fileName = "sd_" + str(time.time()) + '.png'
46
+ # image.save("/code/tmpdir/" + fileName)
47
+
48
+ print(fileName)
49
+
50
+ return {"status": "OK", "file": fileName}
51
  else:
52
  return {"status": "SORRY! This file is member only.", "file": ""}