Spaces:
Build error
Build error
getting started with django
Browse files- app.py +17 -23
- db.sqlite3 +0 -0
- hf-stickers/__init__.py +0 -0
- hf-stickers/__pycache__/__init__.cpython-310.pyc +0 -0
- hf-stickers/__pycache__/settings.cpython-310.pyc +0 -0
- hf-stickers/__pycache__/wsgi.cpython-310.pyc +0 -0
- hf-stickers/asgi.py +16 -0
- hf-stickers/settings.py +103 -0
- hf-stickers/urls.py +6 -0
- hf-stickers/wsgi.py +16 -0
- manage.py +22 -0
- management/commands/runserver.py +3 -0
- requirements.txt +3 -1
- webapp/__init__.py +0 -0
- webapp/__pycache__/__init__.cpython-310.pyc +0 -0
- webapp/admin.py +3 -0
- webapp/apps.py +6 -0
- webapp/migrations/__init__.py +0 -0
- webapp/models.py +3 -0
- webapp/tests.py +3 -0
- webapp/urls.py +12 -0
- webapp/views.py +6 -0
app.py
CHANGED
@@ -9,35 +9,29 @@ from dotenv import load_dotenv
|
|
9 |
load_dotenv()
|
10 |
login(token=os.getenv("HF_TOKEN"))
|
11 |
|
12 |
-
pipeline = StableDiffusion3Pipeline.from_pretrained(
|
13 |
-
"stabilityai/stable-diffusion-3-medium",
|
14 |
-
revision="refs/pr/26",
|
15 |
-
torch_dtype=torch.float16,
|
16 |
-
)
|
17 |
-
pipeline.to("cuda")
|
18 |
-
|
19 |
@spaces.GPU
|
20 |
-
def generate(
|
21 |
-
print('start generate'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
return pipeline(
|
23 |
-
prompt
|
24 |
-
|
25 |
-
num_inference_steps=
|
26 |
-
|
27 |
-
width=width,
|
28 |
-
guidance_scale=guidance_scale
|
29 |
).images
|
30 |
|
31 |
|
32 |
gr.Interface(
|
33 |
fn=generate,
|
34 |
-
inputs=
|
35 |
-
gr.Textbox(label="Prompt", lines=3),
|
36 |
-
gr.Textbox(label="Negative Prompt", lines=2),
|
37 |
-
gr.Slider(label="Inference Steps", value=20, minimum=1, maximum=30, step=1),
|
38 |
-
gr.Number(label="Height"),
|
39 |
-
gr.Number(label="Width"),
|
40 |
-
gr.Slider(label="Guidance Scale", value=7, minimum=1, maximum=15, step=1)
|
41 |
-
],
|
42 |
outputs=gr.Gallery(),
|
43 |
).launch()
|
|
|
9 |
load_dotenv()
|
10 |
login(token=os.getenv("HF_TOKEN"))
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
@spaces.GPU
|
13 |
+
def generate():
|
14 |
+
print('start generate')
|
15 |
+
pipeline = StableDiffusion3Pipeline.from_pretrained(
|
16 |
+
"stabilityai/stable-diffusion-3-medium",
|
17 |
+
revision="refs/pr/26",
|
18 |
+
torch_dtype=torch.float16,
|
19 |
+
)
|
20 |
+
|
21 |
+
pipeline.to("cuda")
|
22 |
+
prompt = "A cat took a fish and running in a market"
|
23 |
+
scheduler = DDPMScheduler(beta_start=0.00085, beta_end=0.012,
|
24 |
+
beta_schedule="scaled_linear")
|
25 |
return pipeline(
|
26 |
+
prompt,
|
27 |
+
scheduler=scheduler,
|
28 |
+
num_inference_steps=30,
|
29 |
+
guidance_scale=7.5,
|
|
|
|
|
30 |
).images
|
31 |
|
32 |
|
33 |
gr.Interface(
|
34 |
fn=generate,
|
35 |
+
inputs=gr.Text(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
outputs=gr.Gallery(),
|
37 |
).launch()
|
db.sqlite3
ADDED
File without changes
|
hf-stickers/__init__.py
ADDED
File without changes
|
hf-stickers/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (131 Bytes). View file
|
|
hf-stickers/__pycache__/settings.cpython-310.pyc
ADDED
Binary file (2.16 kB). View file
|
|
hf-stickers/__pycache__/wsgi.cpython-310.pyc
ADDED
Binary file (542 Bytes). View file
|
|
hf-stickers/asgi.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
ASGI config for hf-stickers project.
|
3 |
+
|
4 |
+
It exposes the ASGI callable as a module-level variable named ``application``.
|
5 |
+
|
6 |
+
For more information on this file, see
|
7 |
+
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
|
8 |
+
"""
|
9 |
+
|
10 |
+
import os
|
11 |
+
|
12 |
+
from django.core.asgi import get_asgi_application
|
13 |
+
|
14 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hf-stickers.settings')
|
15 |
+
|
16 |
+
application = get_asgi_application()
|
hf-stickers/settings.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Django settings for hf-stickers project.
|
3 |
+
|
4 |
+
Generated by 'django-admin startproject' using Django 5.0.6.
|
5 |
+
|
6 |
+
For more information on this file, see
|
7 |
+
https://docs.djangoproject.com/en/5.0/topics/settings/
|
8 |
+
|
9 |
+
For the full list of settings and their values, see
|
10 |
+
https://docs.djangoproject.com/en/5.0/ref/settings/
|
11 |
+
"""
|
12 |
+
import os
|
13 |
+
|
14 |
+
from pathlib import Path
|
15 |
+
|
16 |
+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
17 |
+
BASE_DIR = Path(__file__).resolve().parent.parent
|
18 |
+
|
19 |
+
# SECURITY WARNING: don't run with debug turned on in production!
|
20 |
+
DEBUG = True
|
21 |
+
|
22 |
+
ALLOWED_HOSTS = ["*"]
|
23 |
+
CSRF_COOKIE_SECURE = True
|
24 |
+
CSRF_COOKIE_HTTPONLY = True
|
25 |
+
|
26 |
+
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'django-insecure-#7!6z1!')
|
27 |
+
|
28 |
+
# Application definition
|
29 |
+
|
30 |
+
INSTALLED_APPS = [
|
31 |
+
'django.contrib.admin',
|
32 |
+
'django.contrib.auth',
|
33 |
+
'django.contrib.contenttypes',
|
34 |
+
'django.contrib.sessions',
|
35 |
+
'django.contrib.messages',
|
36 |
+
'django.contrib.staticfiles'
|
37 |
+
]
|
38 |
+
|
39 |
+
MIDDLEWARE = [
|
40 |
+
'django.middleware.security.SecurityMiddleware',
|
41 |
+
'django.contrib.sessions.middleware.SessionMiddleware',
|
42 |
+
'django.middleware.common.CommonMiddleware',
|
43 |
+
'django.middleware.csrf.CsrfViewMiddleware',
|
44 |
+
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
45 |
+
'django.contrib.messages.middleware.MessageMiddleware',
|
46 |
+
'django.middleware.clickjacking.XFrameOptionsMiddleware'
|
47 |
+
]
|
48 |
+
|
49 |
+
ROOT_URLCONF = 'hf-stickers.urls'
|
50 |
+
|
51 |
+
SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies"
|
52 |
+
SESSION_COOKIE_HTTPONLY = True
|
53 |
+
|
54 |
+
WSGI_APPLICATION = 'hf-stickers.wsgi.application'
|
55 |
+
|
56 |
+
# Internationalization
|
57 |
+
# https://docs.djangoproject.com/en/5.0/topics/i18n/
|
58 |
+
|
59 |
+
LANGUAGE_CODE = 'en-us'
|
60 |
+
|
61 |
+
TIME_ZONE = 'UTC'
|
62 |
+
|
63 |
+
USE_I18N = True
|
64 |
+
|
65 |
+
USE_TZ = True
|
66 |
+
|
67 |
+
# Default primary key field type
|
68 |
+
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
|
69 |
+
|
70 |
+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
71 |
+
|
72 |
+
LOGGING = {
|
73 |
+
'version': 1,
|
74 |
+
'disable_existing_loggers': False,
|
75 |
+
'formatters': {
|
76 |
+
'verbose': {
|
77 |
+
'format': ('%(asctime)s [%(process)d] [%(levelname)s] ' +
|
78 |
+
'pathname=%(pathname)s lineno=%(lineno)s ' +
|
79 |
+
'funcname=%(funcName)s %(message)s'),
|
80 |
+
'datefmt': '%Y-%m-%d %H:%M:%S'
|
81 |
+
},
|
82 |
+
'simple': {
|
83 |
+
'format': '%(levelname)s %(message)s'
|
84 |
+
}
|
85 |
+
},
|
86 |
+
'handlers': {
|
87 |
+
'null': {
|
88 |
+
'level': 'DEBUG',
|
89 |
+
'class': 'logging.NullHandler',
|
90 |
+
},
|
91 |
+
'console': {
|
92 |
+
'level': 'DEBUG',
|
93 |
+
'class': 'logging.StreamHandler',
|
94 |
+
'formatter': 'verbose'
|
95 |
+
}
|
96 |
+
},
|
97 |
+
'loggers': {
|
98 |
+
'main': {
|
99 |
+
'handlers': ['console'],
|
100 |
+
'level': 'DEBUG',
|
101 |
+
}
|
102 |
+
}
|
103 |
+
}
|
hf-stickers/urls.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.contrib import admin
|
2 |
+
from django.urls import include, path
|
3 |
+
|
4 |
+
urlpatterns = [
|
5 |
+
path("", include("webapp.urls"))
|
6 |
+
]
|
hf-stickers/wsgi.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
WSGI config for hf-stickers project.
|
3 |
+
|
4 |
+
It exposes the WSGI callable as a module-level variable named ``application``.
|
5 |
+
|
6 |
+
For more information on this file, see
|
7 |
+
https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
|
8 |
+
"""
|
9 |
+
|
10 |
+
import os
|
11 |
+
|
12 |
+
from django.core.wsgi import get_wsgi_application
|
13 |
+
|
14 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hf-stickers.settings')
|
15 |
+
|
16 |
+
application = get_wsgi_application()
|
manage.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
"""Django's command-line utility for administrative tasks."""
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
|
6 |
+
|
7 |
+
def main():
|
8 |
+
"""Run administrative tasks."""
|
9 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hf-stickers.settings')
|
10 |
+
try:
|
11 |
+
from django.core.management import execute_from_command_line
|
12 |
+
except ImportError as exc:
|
13 |
+
raise ImportError(
|
14 |
+
"Couldn't import Django. Are you sure it's installed and "
|
15 |
+
"available on your PYTHONPATH environment variable? Did you "
|
16 |
+
"forget to activate a virtual environment?"
|
17 |
+
) from exc
|
18 |
+
execute_from_command_line(sys.argv)
|
19 |
+
|
20 |
+
|
21 |
+
if __name__ == '__main__':
|
22 |
+
main()
|
management/commands/runserver.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.core.management.commands.runserver import Command as runserver
|
2 |
+
class Command(runserver):
|
3 |
+
default_port = "7680"
|
requirements.txt
CHANGED
@@ -5,4 +5,6 @@ accelerate
|
|
5 |
python-dotenv
|
6 |
numpy<2.0.0,>=1.20.0
|
7 |
sentencepiece
|
8 |
-
gradio
|
|
|
|
|
|
5 |
python-dotenv
|
6 |
numpy<2.0.0,>=1.20.0
|
7 |
sentencepiece
|
8 |
+
gradio
|
9 |
+
django
|
10 |
+
gunicorn
|
webapp/__init__.py
ADDED
File without changes
|
webapp/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (126 Bytes). View file
|
|
webapp/admin.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.contrib import admin
|
2 |
+
|
3 |
+
# Register your models here.
|
webapp/apps.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.apps import AppConfig
|
2 |
+
|
3 |
+
|
4 |
+
class WebappConfig(AppConfig):
|
5 |
+
default_auto_field = 'django.db.models.BigAutoField'
|
6 |
+
name = 'webapp'
|
webapp/migrations/__init__.py
ADDED
File without changes
|
webapp/models.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.db import models
|
2 |
+
|
3 |
+
# Create your models here.
|
webapp/tests.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.test import TestCase
|
2 |
+
|
3 |
+
# Create your tests here.
|
webapp/urls.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.urls import path
|
2 |
+
|
3 |
+
from . import views
|
4 |
+
|
5 |
+
urlpatterns = [
|
6 |
+
path("", views.index, name="index"),
|
7 |
+
path("generate-image", views.generate_image, name="generate_image"),
|
8 |
+
path("improve-prompt", views.improve_prompt, name="improve_prompt"),
|
9 |
+
path("get-random-prompt", views.get_random_prompt, name="get_random_prompt"),
|
10 |
+
path("login", views.login, name="login"),
|
11 |
+
path("oauth/callback", views.oauth_callback, name="oauth_callback"),
|
12 |
+
]
|
webapp/views.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.http import HttpResponse
|
2 |
+
|
3 |
+
logger = logging.getLogger('main')
|
4 |
+
|
5 |
+
def index(request):
|
6 |
+
return HttpResponse('Hello!', {}, request)
|