Yaro99 commited on
Commit
94cc783
verified
1 Parent(s): 2260ec1

Update app.py for Docker

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -1,16 +1,16 @@
1
- import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Cargar el modelo preentrenado DistilBERT
5
- pipe = pipeline("text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
6
 
7
- # Funci贸n para realizar predicci贸n
8
- def predict(text):
9
- result = pipe(text)
10
- return result[0]['label'], result[0]['score']
11
 
12
- # Interfaz de usuario de Gradio
13
- interface = gr.Interface(fn=predict, inputs="text", outputs=["text", "text"])
 
14
 
15
- # Correr la interfaz
16
- interface.launch()
 
 
 
1
+ from fastapi import FastAPI
2
  from transformers import pipeline
3
 
4
+ app = FastAPI()
 
5
 
6
+ # Cargar el modelo DistilBERT para clasificaci贸n de texto
7
+ classifier = pipeline("text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
 
 
8
 
9
+ @app.get("/")
10
+ def greet_json():
11
+ return {"Hello": "World!"}
12
 
13
+ @app.post("/predict/")
14
+ def predict(text: str):
15
+ result = classifier(text)
16
+ return {"label": result[0]['label'], "score": result[0]['score']}