Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import joblib
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Load the model and vectorizer
|
5 |
+
model = joblib.load('scripts/modeli/logistic_regression_model.pkl')
|
6 |
+
vectorizer = joblib.load('scripts/modeli/tfidf_vectorizer.pkl')
|
7 |
+
|
8 |
+
def predict_review_rating(review_text):
|
9 |
+
# Transform the review text using the loaded vectorizer
|
10 |
+
review_tfidf = vectorizer.transform([review_text])
|
11 |
+
|
12 |
+
# Make prediction
|
13 |
+
prediction = model.predict(review_tfidf)
|
14 |
+
|
15 |
+
return prediction[0]
|
16 |
+
|
17 |
+
# Create the Gradio interface
|
18 |
+
interface = gr.Interface(
|
19 |
+
fn=predict_review_rating,
|
20 |
+
inputs=gr.Textbox(label="Enter Review Text"),
|
21 |
+
outputs=gr.Textbox(label="Predicted Rating"),
|
22 |
+
title="TripAdvisor Review Rating Predictor",
|
23 |
+
description="Enter a TripAdvisor review and get the predicted rating (1-5)."
|
24 |
+
)
|
25 |
+
|
26 |
+
# Launch the interface
|
27 |
+
interface.launch()
|