Spaces:
Paused
Paused
error handling
Browse files
app.py
CHANGED
|
@@ -28,7 +28,7 @@ def scrape(URL, max_reviews=LIMIT):
|
|
| 28 |
"basicInfo"
|
| 29 |
]["id"]
|
| 30 |
except:
|
| 31 |
-
|
| 32 |
else:
|
| 33 |
all_reviews = []
|
| 34 |
page = 1
|
|
@@ -80,14 +80,17 @@ def generate(URL, query):
|
|
| 80 |
# Get reviews
|
| 81 |
try:
|
| 82 |
reviews = scrape(URL)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
# Clean reviews
|
| 84 |
cleaned_reviews = clean(reviews)
|
| 85 |
# Load data
|
| 86 |
loader = DataFrameLoader(cleaned_reviews, page_content_column="comment")
|
| 87 |
documents = loader.load()
|
| 88 |
except Exception as e:
|
| 89 |
-
|
| 90 |
-
raise gr.Error("Error getting reviews: " + str(e))
|
| 91 |
else:
|
| 92 |
# Split text
|
| 93 |
text_splitter = RecursiveCharacterTextSplitter(
|
|
@@ -118,5 +121,6 @@ gr.Interface(
|
|
| 118 |
outputs=gr.Textbox(label="Jawaban"),
|
| 119 |
title="RingkasUlas",
|
| 120 |
description="Bot percakapan yang bisa meringkas ulasan-ulasan produk di Tokopedia Indonesia (https://tokopedia.com/). Harap bersabar, bot ini dapat memakan waktu agak lama saat mengambil ulasan dari Tokopedia dan menyiapkan jawabannya.",
|
| 121 |
-
allow_flagging="never"
|
|
|
|
| 122 |
).launch()
|
|
|
|
| 28 |
"basicInfo"
|
| 29 |
]["id"]
|
| 30 |
except:
|
| 31 |
+
return "Invalid URL"
|
| 32 |
else:
|
| 33 |
all_reviews = []
|
| 34 |
page = 1
|
|
|
|
| 80 |
# Get reviews
|
| 81 |
try:
|
| 82 |
reviews = scrape(URL)
|
| 83 |
+
if (reviews is None) or (len(reviews) == 0):
|
| 84 |
+
return "No reviews found"
|
| 85 |
+
elif reviews == "Invalid URL":
|
| 86 |
+
return "Invalid URL"
|
| 87 |
# Clean reviews
|
| 88 |
cleaned_reviews = clean(reviews)
|
| 89 |
# Load data
|
| 90 |
loader = DataFrameLoader(cleaned_reviews, page_content_column="comment")
|
| 91 |
documents = loader.load()
|
| 92 |
except Exception as e:
|
| 93 |
+
return "Error getting reviews: " + str(e)
|
|
|
|
| 94 |
else:
|
| 95 |
# Split text
|
| 96 |
text_splitter = RecursiveCharacterTextSplitter(
|
|
|
|
| 121 |
outputs=gr.Textbox(label="Jawaban"),
|
| 122 |
title="RingkasUlas",
|
| 123 |
description="Bot percakapan yang bisa meringkas ulasan-ulasan produk di Tokopedia Indonesia (https://tokopedia.com/). Harap bersabar, bot ini dapat memakan waktu agak lama saat mengambil ulasan dari Tokopedia dan menyiapkan jawabannya.",
|
| 124 |
+
allow_flagging="never",
|
| 125 |
+
|
| 126 |
).launch()
|