File size: 1,015 Bytes
b29073e
9232c88
 
53e95b3
9232c88
860d6f8
9232c88
860d6f8
1ba8781
 
b2a0dd6
 
1ba8781
 
 
 
9232c88
860d6f8
9232c88
 
1ba8781
 
 
9232c88
860d6f8
9232c88
1ba8781
 
53e95b3
 
1ba8781
 
 
19bd4b4
53e95b3
 
708b464
9232c88
1ba8781
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gradio as gr
from fastapi import FastAPI
from transformers import pipeline
from fastapi.middleware.wsgi import WSGIMiddleware

app = FastAPI(title="Company Reputation API")

# Carica modello
model_path="AChierici84/sentiment-roberta-finetuned"
sentiment_task = None

def get_pipeline():
    global sentiment_task
    if sentiment_task is None:
        sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)
    return sentiment_task

@app.get("/")
def root():
    return {
        "status" : "OK",
        "message": "Company reputation alive! API documentation on /docs."
        }

@app.post("/predict")
def predict(text: str):
    pipeline_model = get_pipeline()
    return pipeline_model(text)
    
# Gradio
def analyze(text):
    pipeline_model = get_pipeline()
    return pipeline_model(text)

demo = gr.Interface(fn=analyze, inputs="text", outputs="text")
demo.launch()


#if __name__ == "__main__":
#    import uvicorn
#    uvicorn.run(app, host="0.0.0.0", port=8000)