Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
H
Hydra Node Http
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Hydra Node Http
Commits
50ab3299
Commit
50ab3299
authored
Jul 30, 2022
by
novelailab
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restore normal endpoint
parent
4a2f7481
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
1 deletion
+35
-1
main.py
main.py
+35
-1
No files found.
main.py
View file @
50ab3299
...
@@ -70,7 +70,7 @@ class GenerationOutput(BaseModel):
...
@@ -70,7 +70,7 @@ class GenerationOutput(BaseModel):
class
ErrorOutput
(
BaseModel
):
class
ErrorOutput
(
BaseModel
):
error
:
str
error
:
str
@
app
.
post
(
'/generate'
,
response_model
=
Union
[
Response
,
ErrorOutput
])
@
app
.
post
(
'/generate
-stream
'
,
response_model
=
Union
[
Response
,
ErrorOutput
])
def
generate
(
request
:
GenerationRequest
):
def
generate
(
request
:
GenerationRequest
):
t
=
time
.
perf_counter
()
t
=
time
.
perf_counter
()
print
(
request
)
print
(
request
)
...
@@ -114,5 +114,39 @@ def generate(request: GenerationRequest):
...
@@ -114,5 +114,39 @@ def generate(request: GenerationRequest):
os
.
kill
(
mainpid
,
signal
.
SIGTERM
)
os
.
kill
(
mainpid
,
signal
.
SIGTERM
)
return
{
"error"
:
str
(
e
)}
return
{
"error"
:
str
(
e
)}
@
app
.
post
(
'/generate'
,
response_model
=
Union
[
GenerationOutput
,
ErrorOutput
])
def
generate
(
request
:
GenerationRequest
):
t
=
time
.
perf_counter
()
print
(
request
)
try
:
output
=
sanitize_input
(
request
)
if
output
[
0
]:
request
=
output
[
1
]
else
:
return
ErrorOutput
(
error
=
output
[
1
])
images
=
model
.
sample
(
request
)
for
x
in
range
(
len
(
images
)):
image
=
simplejpeg
.
encode_jpeg
(
images
[
x
],
quality
=
95
)
#get base64 of image
image
=
base64
.
b64encode
(
image
)
.
decode
(
"ascii"
)
images
[
x
]
=
image
process_time
=
time
.
perf_counter
()
-
t
logger
.
info
(
f
"Request took {process_time:0.3f} seconds"
)
return
GenerationOutput
(
output
=
images
)
except
Exception
as
e
:
capture_exception
(
e
)
logger
.
error
(
str
(
e
))
e_s
=
str
(
e
)
gc
.
collect
()
if
"CUDA out of memory"
in
e_s
or
\
"an illegal memory access"
in
e_s
or
"CUDA"
in
e_s
:
logger
.
error
(
"GPU error, committing seppuku."
)
os
.
kill
(
mainpid
,
signal
.
SIGTERM
)
return
{
"error"
:
str
(
e
)}
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
uvicorn
.
run
(
"main:app"
,
host
=
"0.0.0.0"
,
port
=
80
,
log_level
=
"info"
)
uvicorn
.
run
(
"main:app"
,
host
=
"0.0.0.0"
,
port
=
80
,
log_level
=
"info"
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment