Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,8 @@ from transformers import BlipProcessor, BlipForConditionalGeneration # 4. BLIP
|
|
| 5 |
from PIL import Image # 5. Pillow for image processing
|
| 6 |
import openai # 6. OpenAI library for DALL路E API calls
|
| 7 |
import os # 7. OS for environment variables
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# 8. Create the FastAPI app
|
| 10 |
app = FastAPI()
|
|
@@ -23,13 +25,18 @@ async def generate(
|
|
| 23 |
style: str = Form("chibi"), # 13. The desired style (chibi/anime/cartoon), defaults to "chibi"
|
| 24 |
):
|
| 25 |
# 14. Load and convert the uploaded image to RGB
|
| 26 |
-
img_bytes = await image.read()
|
| 27 |
-
img = Image.open(io.BytesIO(img_bytes)).convert("RGB")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
inputs = processor(img, return_tensors="pt")
|
| 31 |
-
out = model.generate(**inputs)
|
| 32 |
-
caption = processor.decode(out[0], skip_special_tokens=True)
|
| 33 |
|
| 34 |
# 16. Construct the DALL路E prompt using the style and the caption
|
| 35 |
prompt = (
|
|
|
|
| 5 |
from PIL import Image # 5. Pillow for image processing
|
| 6 |
import openai # 6. OpenAI library for DALL路E API calls
|
| 7 |
import os # 7. OS for environment variables
|
| 8 |
+
from face_to_prompt import extract_face_prompt
|
| 9 |
+
|
| 10 |
|
| 11 |
# 8. Create the FastAPI app
|
| 12 |
app = FastAPI()
|
|
|
|
| 25 |
style: str = Form("chibi"), # 13. The desired style (chibi/anime/cartoon), defaults to "chibi"
|
| 26 |
):
|
| 27 |
# 14. Load and convert the uploaded image to RGB
|
| 28 |
+
# img_bytes = await image.read()
|
| 29 |
+
# img = Image.open(io.BytesIO(img_bytes)).convert("RGB")
|
| 30 |
+
|
| 31 |
+
# # 15. Caption the image using BLIP
|
| 32 |
+
# inputs = processor(img, return_tensors="pt")
|
| 33 |
+
# out = model.generate(**inputs)
|
| 34 |
+
# caption = processor.decode(out[0], skip_special_tokens=True)
|
| 35 |
+
|
| 36 |
+
with open("temp_input.jpg", "wb") as f:
|
| 37 |
+
f.write(await image.read())
|
| 38 |
|
| 39 |
+
caption = extract_face_prompt("temp_input.jpg")
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# 16. Construct the DALL路E prompt using the style and the caption
|
| 42 |
prompt = (
|