Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jaime Collado
/
api_birads
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
c82b3634
authored
Mar 01, 2023
by
Jaime Collado
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Updated output predictions and README
parent
ba33c58c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
11 deletions
README.md
app.py
main.py
requirements.txt
schemas.py
README.md
View file @
c82b3634
# PiRADS API
# BiRADS 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:
...
@@ -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 @
c82b3634
...
@@ -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,16 @@ def _predict(text, model, vectorizer):
...
@@ -41,8 +42,16 @@ 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}"
for
i
in
range
(
7
)]
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
...
@@ -50,7 +59,7 @@ def _predict(text, model, vectorizer):
...
@@ -50,7 +59,7 @@ def _predict(text, model, vectorizer):
def
register
(
user
:
schemas
.
UserCreate
,
db
:
Session
=
Depends
(
dependencies
.
get_db
)):
def
register
(
user
:
schemas
.
UserCreate
,
db
:
Session
=
Depends
(
dependencies
.
get_db
)):
db_user
=
crud
.
get_user
(
db
,
username
=
user
.
username
)
db_user
=
crud
.
get_user
(
db
,
username
=
user
.
username
)
if
db_user
:
if
db_user
:
raise
HTTPException
(
status_code
=
400
,
detail
=
"
Email
already registered"
)
raise
HTTPException
(
status_code
=
400
,
detail
=
"
Username
already registered"
)
return
crud
.
create_user
(
db
=
db
,
user
=
user
)
return
crud
.
create_user
(
db
=
db
,
user
=
user
)
@app.post
(
"/token"
,
response_model
=
schemas
.
Token
)
@app.post
(
"/token"
,
response_model
=
schemas
.
Token
)
...
...
main.py
View file @
c82b3634
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
=
1447
,
log_level
=
'info'
)
parser
=
argparse
.
ArgumentParser
()
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'
)
requirements.txt
View file @
c82b3634
...
@@ -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 @
c82b3634
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