Spaces:
Sleeping
Sleeping
Commit
·
27cedc0
1
Parent(s):
b2e8e2a
Test with pipeline function
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ from fastapi import FastAPI
|
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
| 10 |
from pydantic import BaseModel
|
| 11 |
from fastapi import Query
|
|
|
|
| 12 |
|
| 13 |
from helper import generate_random_predictions
|
| 14 |
|
|
@@ -51,6 +52,9 @@ class PredictionInput(BaseModel):
|
|
| 51 |
listPricePerUnitMl: float
|
| 52 |
weightPerUnitMl: float
|
| 53 |
|
|
|
|
|
|
|
|
|
|
| 54 |
@app.get("/")
|
| 55 |
def read_root():
|
| 56 |
return {"Hello": "World"}
|
|
@@ -83,6 +87,22 @@ def get_prediction_from_jobrun():
|
|
| 83 |
print("Status Code:", response.status_code)
|
| 84 |
return response.text
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
@app.post("/get_prediction_on_userinput")
|
| 87 |
def run_pred_pipeline(input: PredictionInput):
|
| 88 |
|
|
|
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
| 10 |
from pydantic import BaseModel
|
| 11 |
from fastapi import Query
|
| 12 |
+
from transformers import pipeline
|
| 13 |
|
| 14 |
from helper import generate_random_predictions
|
| 15 |
|
|
|
|
| 52 |
listPricePerUnitMl: float
|
| 53 |
weightPerUnitMl: float
|
| 54 |
|
| 55 |
+
class inputtext(BaseModel):
|
| 56 |
+
inputtext:str
|
| 57 |
+
|
| 58 |
@app.get("/")
|
| 59 |
def read_root():
|
| 60 |
return {"Hello": "World"}
|
|
|
|
| 87 |
print("Status Code:", response.status_code)
|
| 88 |
return response.text
|
| 89 |
|
| 90 |
+
classifier = pipeline("sentiment-analysis") # Defaults to distilbert-base-uncased-finetuned-sst-2-english
|
| 91 |
+
|
| 92 |
+
@app.post("/get_sentiment")
|
| 93 |
+
def get_sentiment_details(input: inputtext):
|
| 94 |
+
|
| 95 |
+
result = classifier(input)
|
| 96 |
+
print(result) # Output will be a list: [{'label': 'POSITIVE', 'score': 0.999...}]
|
| 97 |
+
|
| 98 |
+
# Accessing the results:
|
| 99 |
+
label = result[0]['label']
|
| 100 |
+
score = result[0]['score']
|
| 101 |
+
print(f"Sentiment: {label}, Score: {score}")
|
| 102 |
+
|
| 103 |
+
return label, score
|
| 104 |
+
|
| 105 |
+
|
| 106 |
@app.post("/get_prediction_on_userinput")
|
| 107 |
def run_pred_pipeline(input: PredictionInput):
|
| 108 |
|