Spaces:
Sleeping
Sleeping
Commit
•
1a628fd
1
Parent(s):
6988a7f
Upload 6 files
Browse files- .gitignore +2 -0
- app.py +88 -0
- images/helicopter.jpg +0 -0
- images/maxresdefault.jpg +0 -0
- images/police-heli.jpg +0 -0
- requirements.txt +75 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.venv/
|
2 |
+
.env
|
app.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import io
|
3 |
+
from PIL import Image
|
4 |
+
from dotenv import load_dotenv, find_dotenv
|
5 |
+
_ = load_dotenv(find_dotenv()) # read local .env file
|
6 |
+
hf_api_key = os.environ['HF_API_KEY']
|
7 |
+
|
8 |
+
# Helper function
|
9 |
+
import requests, json
|
10 |
+
|
11 |
+
# API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
|
12 |
+
API_URL = "https://api-inference.huggingface.co/models/cloudqi/cqi_text_to_image_pt_v0"
|
13 |
+
|
14 |
+
#Text-to-image endpoint
|
15 |
+
def get_completion(inputs, parameters=None, ENDPOINT_URL=API_URL):
|
16 |
+
headers = {
|
17 |
+
"Authorization": f"Bearer {hf_api_key}",
|
18 |
+
"Content-Type": "application/json"
|
19 |
+
}
|
20 |
+
data = { "inputs": inputs }
|
21 |
+
if parameters is not None:
|
22 |
+
data.update({"parameters": parameters})
|
23 |
+
response = requests.request("POST",ENDPOINT_URL,headers=headers,data=json.dumps(data))
|
24 |
+
return response.content
|
25 |
+
|
26 |
+
import gradio as gr
|
27 |
+
|
28 |
+
def generate(prompt):
|
29 |
+
output = get_completion(prompt)
|
30 |
+
result_image = Image.open(io.BytesIO(output))
|
31 |
+
return result_image
|
32 |
+
|
33 |
+
|
34 |
+
# def loadGUI():
|
35 |
+
# gr.close_all()
|
36 |
+
# demo = gr.Interface(fn=generate,
|
37 |
+
# inputs=[gr.Textbox(label="Your prompt")],
|
38 |
+
# outputs=[gr.Image(label="Result")],
|
39 |
+
# title="Image Generation with Stable Diffusion",
|
40 |
+
# description="Generate any image with Stable Diffusion",
|
41 |
+
# allow_flagging="never",
|
42 |
+
# examples=["the spirit of a tamagotchi wandering in the city of Vienna","a mecha robot in a favela"])
|
43 |
+
|
44 |
+
# demo.launch(share=True)
|
45 |
+
|
46 |
+
import gradio as gr
|
47 |
+
|
48 |
+
def generate(prompt, negative_prompt, steps, guidance, width, height):
|
49 |
+
params = {
|
50 |
+
"negative_prompt": negative_prompt,
|
51 |
+
"num_inference_steps": steps,
|
52 |
+
"guidance_scale": guidance,
|
53 |
+
"width": width,
|
54 |
+
"height": height
|
55 |
+
}
|
56 |
+
|
57 |
+
output = get_completion(prompt, params)
|
58 |
+
pil_image = Image.open(io.BytesIO(output))
|
59 |
+
return pil_image
|
60 |
+
|
61 |
+
def loadGUI():
|
62 |
+
gr.close_all()
|
63 |
+
demo = gr.Interface(fn=generate,
|
64 |
+
inputs=[
|
65 |
+
gr.Textbox(label="Your prompt"),
|
66 |
+
gr.Textbox(label="Negative prompt"),
|
67 |
+
gr.Slider(label="Inference Steps", minimum=1, maximum=100, value=25,
|
68 |
+
info="In how many steps will the denoiser denoise the image?"),
|
69 |
+
gr.Slider(label="Guidance Scale", minimum=1, maximum=20, value=7,
|
70 |
+
info="Controls how much the text prompt influences the result"),
|
71 |
+
gr.Slider(label="Width", minimum=64, maximum=512, step=64, value=512),
|
72 |
+
gr.Slider(label="Height", minimum=64, maximum=512, step=64, value=512),
|
73 |
+
],
|
74 |
+
outputs=[gr.Image(label="Result")],
|
75 |
+
title="Image Generation with Stable Diffusion",
|
76 |
+
description="Generate any image with Stable Diffusion",
|
77 |
+
allow_flagging="never"
|
78 |
+
)
|
79 |
+
|
80 |
+
demo.launch(share=True)
|
81 |
+
|
82 |
+
def main():
|
83 |
+
loadGUI()
|
84 |
+
|
85 |
+
|
86 |
+
if __name__ == "__main__":
|
87 |
+
main()
|
88 |
+
|
images/helicopter.jpg
ADDED
![]() |
images/maxresdefault.jpg
ADDED
![]() |
images/police-heli.jpg
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
accelerate==0.25.0
|
2 |
+
aiofiles==23.2.1
|
3 |
+
altair==5.2.0
|
4 |
+
annotated-types==0.6.0
|
5 |
+
anyio==3.7.1
|
6 |
+
attrs==23.1.0
|
7 |
+
certifi==2023.11.17
|
8 |
+
charset-normalizer==3.3.2
|
9 |
+
click==8.1.7
|
10 |
+
colorama==0.4.6
|
11 |
+
contourpy==1.2.0
|
12 |
+
cycler==0.12.1
|
13 |
+
fastapi==0.104.1
|
14 |
+
ffmpy==0.3.1
|
15 |
+
filelock==3.13.1
|
16 |
+
fonttools==4.46.0
|
17 |
+
fsspec==2023.12.1
|
18 |
+
gradio==4.8.0
|
19 |
+
gradio_client==0.7.1
|
20 |
+
h11==0.14.0
|
21 |
+
httpcore==1.0.2
|
22 |
+
httpx==0.25.2
|
23 |
+
huggingface-hub==0.19.4
|
24 |
+
idna==3.6
|
25 |
+
importlib-resources==6.1.1
|
26 |
+
Jinja2==3.1.2
|
27 |
+
jsonschema==4.20.0
|
28 |
+
jsonschema-specifications==2023.11.2
|
29 |
+
kiwisolver==1.4.5
|
30 |
+
markdown-it-py==3.0.0
|
31 |
+
MarkupSafe==2.1.3
|
32 |
+
matplotlib==3.8.2
|
33 |
+
mdurl==0.1.2
|
34 |
+
mpmath==1.3.0
|
35 |
+
networkx==3.2.1
|
36 |
+
numpy==1.26.2
|
37 |
+
orjson==3.9.10
|
38 |
+
packaging==23.2
|
39 |
+
pandas==2.1.4
|
40 |
+
Pillow==10.1.0
|
41 |
+
psutil==5.9.6
|
42 |
+
pydantic==2.5.2
|
43 |
+
pydantic_core==2.14.5
|
44 |
+
pydub==0.25.1
|
45 |
+
Pygments==2.17.2
|
46 |
+
pyparsing==3.1.1
|
47 |
+
python-dateutil==2.8.2
|
48 |
+
python-dotenv==1.0.0
|
49 |
+
python-multipart==0.0.6
|
50 |
+
pytz==2023.3.post1
|
51 |
+
PyYAML==6.0.1
|
52 |
+
referencing==0.32.0
|
53 |
+
regex==2023.10.3
|
54 |
+
requests==2.31.0
|
55 |
+
rich==13.7.0
|
56 |
+
rpds-py==0.13.2
|
57 |
+
safetensors==0.4.1
|
58 |
+
semantic-version==2.10.0
|
59 |
+
shellingham==1.5.4
|
60 |
+
six==1.16.0
|
61 |
+
sniffio==1.3.0
|
62 |
+
starlette==0.27.0
|
63 |
+
sympy==1.12
|
64 |
+
tokenizers==0.15.0
|
65 |
+
tomlkit==0.12.0
|
66 |
+
toolz==0.12.0
|
67 |
+
torch==2.1.1
|
68 |
+
tqdm==4.66.1
|
69 |
+
transformers==4.35.2
|
70 |
+
typer==0.9.0
|
71 |
+
typing_extensions==4.8.0
|
72 |
+
tzdata==2023.3
|
73 |
+
urllib3==2.1.0
|
74 |
+
uvicorn==0.24.0.post1
|
75 |
+
websockets==11.0.3
|