Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ from pydantic import BaseModel
|
|
4 |
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
5 |
import torch
|
6 |
import uvicorn
|
7 |
-
from threading import Thread
|
8 |
|
9 |
# Configurar FastAPI
|
10 |
app = FastAPI()
|
@@ -39,18 +38,15 @@ async def predict(input: TextInput):
|
|
39 |
|
40 |
return {"entities": entities}
|
41 |
|
42 |
-
# Iniciar el servidor de FastAPI en un hilo separado
|
43 |
-
def start_api():
|
44 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
45 |
-
|
46 |
-
api_thread = Thread(target=start_api, daemon=True)
|
47 |
-
api_thread.start()
|
48 |
-
|
49 |
# Configurar Gradio
|
50 |
def predict_gradio(text):
|
51 |
-
response = requests.post("http://
|
52 |
entities = response.json().get("entities", [])
|
53 |
return entities
|
54 |
|
55 |
demo = gr.Interface(fn=predict_gradio, inputs="text", outputs="json")
|
56 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
4 |
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
5 |
import torch
|
6 |
import uvicorn
|
|
|
7 |
|
8 |
# Configurar FastAPI
|
9 |
app = FastAPI()
|
|
|
38 |
|
39 |
return {"entities": entities}
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
# Configurar Gradio
|
42 |
def predict_gradio(text):
|
43 |
+
response = requests.post("http://localhost:8000/predict", json={"text": text})
|
44 |
entities = response.json().get("entities", [])
|
45 |
return entities
|
46 |
|
47 |
demo = gr.Interface(fn=predict_gradio, inputs="text", outputs="json")
|
48 |
+
demo.launch(share=True)
|
49 |
+
|
50 |
+
# Iniciar el servidor de FastAPI
|
51 |
+
if __name__ == "__main__":
|
52 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|