Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from outscraper import ApiClient
|
| 3 |
+
|
| 4 |
+
# Initialize the API Client with your API key
|
| 5 |
+
api_client = ApiClient(api_key='YOUR-API-KEY')
|
| 6 |
+
|
| 7 |
+
def fetch_reviews(place: str, reviews_limit: int, ranking: str):
|
| 8 |
+
# Call the Outscraper API
|
| 9 |
+
results = api_client.google_maps_reviews(place, reviews_limit=reviews_limit, sort=ranking)
|
| 10 |
+
|
| 11 |
+
# Process and format the results for display
|
| 12 |
+
if results.get("status") == "Success":
|
| 13 |
+
reviews = results.get("data", [])
|
| 14 |
+
formatted_reviews = "\n\n".join([review.get("text", "") for review in reviews])
|
| 15 |
+
return formatted_reviews
|
| 16 |
+
else:
|
| 17 |
+
return "Error fetching reviews. Please try again."
|
| 18 |
+
|
| 19 |
+
# Define Gradio Interface
|
| 20 |
+
interface = gr.Interface(
|
| 21 |
+
fn=fetch_reviews,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.inputs.Textbox(label="Google Maps Place", default="The NoMad Restaurant, NY, USA"),
|
| 24 |
+
gr.inputs.Number(label="Number of Reviews", default=3, min=1, max=100),
|
| 25 |
+
gr.inputs.Dropdown(choices=["most_relevant", "newest", "highest_rating", "lowest_rating"], label="Reviews Ranking Type", default="most_relevant")
|
| 26 |
+
],
|
| 27 |
+
outputs=gr.outputs.Textbox(),
|
| 28 |
+
live=True,
|
| 29 |
+
title="Google Maps Reviews Fetcher",
|
| 30 |
+
description="Fetch reviews from Google Maps based on your criteria."
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# If you're testing locally:
|
| 34 |
+
# interface.launch()
|
| 35 |
+
|
| 36 |
+
# If deploying to Hugging Face Spaces:
|
| 37 |
+
interface.serve()
|