Spaces:
Sleeping
Sleeping
hardik-kanzariya
commited on
Commit
•
5ccafa6
1
Parent(s):
9ad20d9
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,9 @@ import nltk
|
|
8 |
import json
|
9 |
import numpy as np
|
10 |
import streamlit as st
|
|
|
|
|
|
|
11 |
|
12 |
nltk.download('wordnet')
|
13 |
# Load your TensorFlow model
|
@@ -52,6 +55,15 @@ def getPrediction(input):
|
|
52 |
|
53 |
def getSentiment(idx):
|
54 |
return {0: "Negative", 1: "Positive", 2: "Neutral"}.get(idx, "Neutral")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
# Streamlit UI
|
57 |
st.title("Sentiment Analysis")
|
|
|
8 |
import json
|
9 |
import numpy as np
|
10 |
import streamlit as st
|
11 |
+
from fastapi import FastAPI, HTTPException
|
12 |
+
|
13 |
+
app = FastAPI()
|
14 |
|
15 |
nltk.download('wordnet')
|
16 |
# Load your TensorFlow model
|
|
|
55 |
|
56 |
def getSentiment(idx):
|
57 |
return {0: "Negative", 1: "Positive", 2: "Neutral"}.get(idx, "Neutral")
|
58 |
+
|
59 |
+
|
60 |
+
@app.post("/predict")
|
61 |
+
async def predict(text: str):
|
62 |
+
prediction, confidence_score = getPrediction(text)
|
63 |
+
return {
|
64 |
+
"prediction": getSentiment(prediction) + " Statement",
|
65 |
+
"confidence": f"{confidence_score * 100:.2f}%"
|
66 |
+
}
|
67 |
|
68 |
# Streamlit UI
|
69 |
st.title("Sentiment Analysis")
|