Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# Specify the filename for your PKL file
|
| 4 |
+
filename = 'sentiment_model.pkl'
|
| 5 |
+
|
| 6 |
+
# Open the file in write binary ('wb') mode and save the model using pickle.dump()
|
| 7 |
+
with open(filename, 'wb') as file:
|
| 8 |
+
pickle.dump(nb_classifier, file)
|
| 9 |
+
|
| 10 |
+
def predict_sentiment(text_input):
|
| 11 |
+
text_vector = vectorizer.transform([text])
|
| 12 |
+
prediction = nb_classifier.predict(text_vector)
|
| 13 |
+
return "Positive" if prediction == 1 else "Negative"
|
| 14 |
+
|
| 15 |
+
# Test sample
|
| 16 |
+
|
| 17 |
+
with gr.Blocks(theme="compact") as demo:
|
| 18 |
+
gr.Markdown("predict_sentiment")
|
| 19 |
+
#chatbot_window = gr.Chatbot(label="")
|
| 20 |
+
with gr.Row():
|
| 21 |
+
# Corrected 'lable' to 'label'
|
| 22 |
+
text_input = gr.Textbox(label="Write the Review", placeholder="Enter your sentiment", show_label=False)
|
| 23 |
+
# Create a Textbox to display the output
|
| 24 |
+
output_box = gr.Textbox(label="Sentiment Prediction")
|
| 25 |
+
# Submit the input to the function and display the output in the output_box
|
| 26 |
+
text_input.submit(fn=predict_sentiment, inputs=text_input, outputs=output_box)
|
| 27 |
+
demo.launch(share=True
|