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
ae1c6d94
Commit
ae1c6d94
authored
Jul 30, 2022
by
novelailab
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no middleware
parent
e317d55a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
18 deletions
+3
-18
main.py
main.py
+3
-18
No files found.
main.py
View file @
ae1c6d94
...
@@ -61,7 +61,7 @@ class ErrorOutput(BaseModel):
...
@@ -61,7 +61,7 @@ class ErrorOutput(BaseModel):
@
app
.
post
(
'/generate'
,
response_model
=
Union
[
GenerationOutput
,
ErrorOutput
])
@
app
.
post
(
'/generate'
,
response_model
=
Union
[
GenerationOutput
,
ErrorOutput
])
def
generate
(
request
:
GenerationRequest
):
def
generate
(
request
:
GenerationRequest
):
t
=
time
.
perf_counter
()
print
(
request
)
print
(
request
)
try
:
try
:
output
=
sanitize_input
(
request
)
output
=
sanitize_input
(
request
)
...
@@ -72,6 +72,8 @@ def generate(request: GenerationRequest):
...
@@ -72,6 +72,8 @@ def generate(request: GenerationRequest):
return
{
'error'
:
output
[
1
]}
return
{
'error'
:
output
[
1
]}
images
=
model
.
sample
(
request
)
images
=
model
.
sample
(
request
)
process_time
=
time
.
perf_counter
()
-
t
logger
.
info
(
f
"Request took {process_time:0.3f} seconds"
)
return
{
"generations"
:
images
}
return
{
"generations"
:
images
}
except
Exception
as
e
:
except
Exception
as
e
:
...
@@ -85,22 +87,5 @@ def generate(request: GenerationRequest):
...
@@ -85,22 +87,5 @@ def generate(request: GenerationRequest):
os
.
kill
(
os
.
getpid
(),
signal
.
SIGTERM
)
os
.
kill
(
os
.
getpid
(),
signal
.
SIGTERM
)
return
{
"error"
:
str
(
e
)}
return
{
"error"
:
str
(
e
)}
@
app
.
middleware
(
"http"
)
async
def
handle_logging_and_errors
(
request
:
Request
,
call_next
):
t
=
time
.
perf_counter
()
response
=
await
call_next
(
request
)
process_time
=
time
.
perf_counter
()
-
t
response
.
headers
[
"X-Process-Time"
]
=
str
(
process_time
)
logger
.
info
(
f
"Request took {t:0.3f} seconds"
)
f
=
open
(
"/tmp/health_readiness"
,
"w"
)
f
.
close
()
if
os
.
environ
[
'DEV'
]
==
"False"
:
f
=
open
(
"/tmp/healthy"
,
"w"
)
f
.
close
()
return
response
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