Spaces:
Sleeping
Sleeping
Commit
·
4a0119a
1
Parent(s):
607700a
made inputs clearer and better
Browse files
app.py
CHANGED
|
@@ -63,7 +63,7 @@ def to_list(x):
|
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
-
def reddit_hack(keyword, *, subreddits=None):
|
| 67 |
|
| 68 |
#sub_reddit_list = ["legaladviceuk", "housinguk", "ukpersonalfinance"]#
|
| 69 |
sub_reddit_list = to_list(subreddits)
|
|
@@ -82,9 +82,9 @@ def reddit_hack(keyword, *, subreddits=None):
|
|
| 82 |
# Query parameters
|
| 83 |
params = {
|
| 84 |
"q": keyword, # Search query
|
| 85 |
-
"limit":
|
| 86 |
"sort": "relevance", # Sort by relevance
|
| 87 |
-
"t": "
|
| 88 |
"restrict_sr": "true", # Restrict to the subreddit
|
| 89 |
"include_facets": "false", # Don't include facets
|
| 90 |
"sr_detail": "false", # Don't expand subreddit details
|
|
@@ -133,9 +133,9 @@ def reddit_hack(keyword, *, subreddits=None):
|
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
-
def main(keyword, subreddits):
|
| 137 |
print(f"subreddits are {subreddits}")
|
| 138 |
-
result = reddit_hack(keyword, subreddits=subreddits)
|
| 139 |
return result
|
| 140 |
|
| 141 |
#reddit_hack("ccj", subreddits="legaladviceuk, housinguk, ukpersonalfinance")
|
|
@@ -145,8 +145,12 @@ def main(keyword, subreddits):
|
|
| 145 |
|
| 146 |
demo = gr.Interface(
|
| 147 |
fn=main,
|
| 148 |
-
inputs=[
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
title="redditHack",
|
| 151 |
description="enter keyword, and comma seerate string of subreddits"
|
| 152 |
)
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
+
def reddit_hack(keyword, count=10, *, subreddits=None):
|
| 67 |
|
| 68 |
#sub_reddit_list = ["legaladviceuk", "housinguk", "ukpersonalfinance"]#
|
| 69 |
sub_reddit_list = to_list(subreddits)
|
|
|
|
| 82 |
# Query parameters
|
| 83 |
params = {
|
| 84 |
"q": keyword, # Search query
|
| 85 |
+
"limit": count, # Max number of results (up to 100)
|
| 86 |
"sort": "relevance", # Sort by relevance
|
| 87 |
+
"t": "year", # Time filter
|
| 88 |
"restrict_sr": "true", # Restrict to the subreddit
|
| 89 |
"include_facets": "false", # Don't include facets
|
| 90 |
"sr_detail": "false", # Don't expand subreddit details
|
|
|
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
+
def main(keyword, count, subreddits):
|
| 137 |
print(f"subreddits are {subreddits}")
|
| 138 |
+
result = reddit_hack(keyword, count, subreddits=subreddits)
|
| 139 |
return result
|
| 140 |
|
| 141 |
#reddit_hack("ccj", subreddits="legaladviceuk, housinguk, ukpersonalfinance")
|
|
|
|
| 145 |
|
| 146 |
demo = gr.Interface(
|
| 147 |
fn=main,
|
| 148 |
+
inputs=[
|
| 149 |
+
gr.Textbox(label="Keyword", placeholder="e.g., ccj"),
|
| 150 |
+
gr.Number(label="Max posts", precision=0, minimum=1, value=10),
|
| 151 |
+
gr.Textbox(label="Subreddits (comma-separated)", placeholder="music, indieheads")
|
| 152 |
+
],
|
| 153 |
+
outputs=gr.Textbox(label="Result"),
|
| 154 |
title="redditHack",
|
| 155 |
description="enter keyword, and comma seerate string of subreddits"
|
| 156 |
)
|