File size: 789 Bytes
3e6be2c
 
 
 
7258f72
 
3e6be2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import joblib
import gradio as gr

# Load the model and vectorizer
model = joblib.load('logistic_regression_model.pkl')
vectorizer = joblib.load('tfidf_vectorizer.pkl')

def predict_review_rating(review_text):
    # Transform the review text using the loaded vectorizer
    review_tfidf = vectorizer.transform([review_text])
    
    # Make prediction
    prediction = model.predict(review_tfidf)
    
    return prediction[0]

# Create the Gradio interface
interface = gr.Interface(
    fn=predict_review_rating,
    inputs=gr.Textbox(label="Enter Review Text"),
    outputs=gr.Textbox(label="Predicted Rating"),
    title="TripAdvisor Review Rating Predictor",
    description="Enter a TripAdvisor review and get the predicted rating (1-5)."
)

# Launch the interface
interface.launch()