Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jaime Collado
/
api_pirads
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3b604dad
authored
Mar 01, 2023
by
Jaime Collado
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Updated README and output predictions
parent
1b487c30
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
11 deletions
README.md
app.py
main.py
requirements.txt
schemas.py
README.md
View file @
3b604dad
# PiRADS API
# PiRADS API
## Compatibilidad
Esta API ha sido desarrollada y probada con la versión de Python 3.9.7.
## Guía de instalación
## Guía de instalación
1.
Configuración:
1.
Configuración:
1.
Renombrar
`config_example.yaml`
a
`config.yaml`
1.
Renombrar
`config_example.yaml`
a
`config.yaml`
...
@@ -7,5 +10,5 @@
...
@@ -7,5 +10,5 @@
2.
Crear un entorno virtual:
`python3 -m venv /path/to/environment`
2.
Crear un entorno virtual:
`python3 -m venv /path/to/environment`
3.
Activar el entorno virtual:
`source /path/to/environment/bin/activate`
3.
Activar el entorno virtual:
`source /path/to/environment/bin/activate`
4.
Instalar las bibliotecas necesarias:
`pip install -r /path/to/requirements.txt`
4.
Instalar las bibliotecas necesarias:
`pip install -r /path/to/requirements.txt`
5.
Lanzar el servicio:
`uvicorn main:app --host <HOST> --port <PORT>`
5.
Lanzar el servicio:
`python main.py [-h] [--host HOST] [--port PORT]`
6.
Probar que funciona en http://localhost:PORT/docs
6.
Probar que funciona accediendo (por defecto) a: http://localhost:8000/docs
\ No newline at end of file
\ No newline at end of file
app.py
View file @
3b604dad
...
@@ -14,8 +14,9 @@ database.Base.metadata.create_all(bind=database.engine)
...
@@ -14,8 +14,9 @@ database.Base.metadata.create_all(bind=database.engine)
# APP
# APP
app
=
FastAPI
()
app
=
FastAPI
()
#app = FastAPI(openapi_url=None) # Disable interactive docs
# CORS middleware
#
Allow all
CORS middleware
app
.
add_middleware
(
app
.
add_middleware
(
CORSMiddleware
,
CORSMiddleware
,
allow_origins
=
[
"*"
],
allow_origins
=
[
"*"
],
...
@@ -41,8 +42,17 @@ def _predict(text, model, vectorizer):
...
@@ -41,8 +42,17 @@ def _predict(text, model, vectorizer):
X_test
=
vectorizer
.
transform
([
clean_text
])
X_test
=
vectorizer
.
transform
([
clean_text
])
# Predict outputs
# Predict outputs
labels
=
[
f
"PR{i+1}"
for
i
in
range
(
5
)]
probs
=
model
.
predict_proba
(
X_test
)
probs
=
model
.
predict_proba
(
X_test
)
probs
=
[
prob
[
0
][
1
]
for
prob
in
probs
]
probs
=
[
prob
[
0
][
1
]
for
prob
in
probs
]
probs
=
[
{
"type"
:
label
,
"percentage"
:
f
"{prob*100:.2f}
%
"
}
for
label
,
prob
in
zip
(
labels
,
probs
)
]
return
probs
return
probs
# Methods
# Methods
...
@@ -132,7 +142,7 @@ Se sugiere correlación estrecha con evolución de parámetros clínicos. Si en
...
@@ -132,7 +142,7 @@ Se sugiere correlación estrecha con evolución de parámetros clínicos. Si en
),
),
current_user
:
str
=
Depends
(
dependencies
.
get_current_active_user
)
current_user
:
str
=
Depends
(
dependencies
.
get_current_active_user
)
):
):
#
Input
data: [{"id": 1, "text": "a"}, {"id": 2, "text": "b"}]
#
input_
data: [{"id": 1, "text": "a"}, {"id": 2, "text": "b"}]
predictions
=
[]
predictions
=
[]
for
report
in
input_data
:
for
report
in
input_data
:
prediction
=
_predict
(
text
=
report
.
text
,
model
=
clf
,
vectorizer
=
vectorizer
)
prediction
=
_predict
(
text
=
report
.
text
,
model
=
clf
,
vectorizer
=
vectorizer
)
...
...
main.py
View file @
3b604dad
import
uvicorn
import
uvicorn
import
argparse
from
app
import
app
from
app
import
app
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
uvicorn
.
run
(
app
,
host
=
'0.0.0.0'
,
port
=
1448
,
log_level
=
'info'
)
parser
=
argparse
.
ArgumentParser
()
\ No newline at end of file
parser
.
add_argument
(
"--host"
,
type
=
str
,
required
=
False
,
default
=
"0.0.0.0"
)
parser
.
add_argument
(
"--port"
,
type
=
int
,
required
=
False
,
default
=
8000
)
args
=
parser
.
parse_args
()
uvicorn
.
run
(
app
,
host
=
args
.
host
,
port
=
args
.
port
,
log_level
=
'info'
)
\ No newline at end of file
requirements.txt
View file @
3b604dad
...
@@ -30,7 +30,7 @@ python-multipart==0.0.5
...
@@ -30,7 +30,7 @@ python-multipart==0.0.5
PyYAML
==6.0
PyYAML
==6.0
rfc3986
==1.5.0
rfc3986
==1.5.0
rsa
==4.9
rsa
==4.9
scikit-learn
==1.
2.1
scikit-learn
==1.
0.2
scipy
==1.10.0
scipy
==1.10.0
six
==1.16.0
six
==1.16.0
sniffio
==1.3.0
sniffio
==1.3.0
...
...
schemas.py
View file @
3b604dad
from
typing
import
List
,
Union
from
typing
import
List
,
Union
,
Dict
from
pydantic
import
BaseModel
from
pydantic
import
BaseModel
...
@@ -33,4 +33,4 @@ class InputData(BaseModel):
...
@@ -33,4 +33,4 @@ class InputData(BaseModel):
class
OutputData
(
BaseModel
):
class
OutputData
(
BaseModel
):
id
:
int
id
:
int
prediction
:
List
[
float
]
prediction
:
List
[
Dict
[
str
,
str
]]
\ No newline at end of file
\ 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