Almahfouz commited on
Commit
63e9c23
1 Parent(s): 5456c53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -17
app.py CHANGED
@@ -39,7 +39,7 @@ def classify_review(user_review):
39
  confidence = sentiment_result['score']
40
  sentiment_based_classification = f"Model prediction: {sentiment} with confidence: {confidence:.2f}"
41
 
42
- return f"{rating_based_classification}\n{sentiment_based_classification}\nMatching Score: {best_score}%"
43
  else:
44
  return "Review not found in the dataset."
45
 
@@ -58,11 +58,7 @@ def plot_rating_distribution():
58
 
59
  # Function to allow users to preview the dataset (first 10 rows)
60
  def preview_dataset():
61
- return reviews_df.head(10) # Return the first 10 rows of the dataset
62
-
63
- # Function to download the dataset
64
- def download_dataset():
65
- return 'Restaurant_reviews.csv' # Provide the path to the dataset for download
66
 
67
  # Create the Gradio interface for classifying reviews
68
  review_interface = gr.Interface(
@@ -73,6 +69,14 @@ review_interface = gr.Interface(
73
  description="Enter a restaurant review. The system will classify it based on the dataset rating and use a sentiment analysis model."
74
  )
75
 
 
 
 
 
 
 
 
 
76
  # Create the Gradio interface for plotting the rating distribution
77
  plot_interface = gr.Interface(
78
  fn=plot_rating_distribution,
@@ -91,20 +95,13 @@ preview_interface = gr.Interface(
91
  description="Displays the first 10 rows of the dataset for preview."
92
  )
93
 
94
- # Create the Gradio interface for downloading the dataset
95
- download_interface = gr.Interface(
96
- fn=download_dataset,
97
- inputs=[],
98
- outputs=gr.File(),
99
- title="Download Restaurant Reviews Dataset",
100
- description="Download the full restaurant reviews dataset in CSV format."
101
- )
102
 
103
  # Combine all interfaces (Review Classifier, Rating Distribution, Dataset Preview, Dataset Download) into tabs
104
  tabbed_interface = gr.TabbedInterface(
105
- [review_interface, plot_interface, preview_interface, download_interface],
106
- ["Review Classifier", "Rating Distribution", "Dataset Preview", "Download Dataset"]
107
  )
108
 
109
  # Launch the Gradio interface
110
- tabbed_interface.launch()
 
39
  confidence = sentiment_result['score']
40
  sentiment_based_classification = f"Model prediction: {sentiment} with confidence: {confidence:.2f}"
41
 
42
+ return f"{rating_based_classification}\n{sentiment_based_classification}\nMatching Score: {best_score}%\nBest Match\n{best_match}"
43
  else:
44
  return "Review not found in the dataset."
45
 
 
58
 
59
  # Function to allow users to preview the dataset (first 10 rows)
60
  def preview_dataset():
61
+ return reviews_df.head(15) # Return the first 10 rows of the dataset
 
 
 
 
62
 
63
  # Create the Gradio interface for classifying reviews
64
  review_interface = gr.Interface(
 
69
  description="Enter a restaurant review. The system will classify it based on the dataset rating and use a sentiment analysis model."
70
  )
71
 
72
+ # Create the Gradio interface for classifying reviews
73
+ review_interface = gr.Interface(
74
+ fn=classify_review,
75
+ inputs=gr.Textbox(lines=2, placeholder="Enter your review here", label="Reviews"),
76
+ outputs="text",
77
+ title="Review Classifier Based on Rating and Hugging Face Model",
78
+ description="Enter a restaurant review. The system will classify it based on the dataset rating and use a sentiment analysis model."
79
+ )
80
  # Create the Gradio interface for plotting the rating distribution
81
  plot_interface = gr.Interface(
82
  fn=plot_rating_distribution,
 
95
  description="Displays the first 10 rows of the dataset for preview."
96
  )
97
 
98
+
 
 
 
 
 
 
 
99
 
100
  # Combine all interfaces (Review Classifier, Rating Distribution, Dataset Preview, Dataset Download) into tabs
101
  tabbed_interface = gr.TabbedInterface(
102
+ [review_interface, plot_interface, preview_interface],
103
+ ["Review Classifier", "Rating Distribution", "Dataset Preview", ""]
104
  )
105
 
106
  # Launch the Gradio interface
107
+ tabbed_interface.launch()