Spaces:
Runtime error
Runtime error
Santiago Martinez
commited on
Commit
·
915892a
1
Parent(s):
995aa82
feat: flask app
Browse files- index.html +0 -24
- static/index.js +1 -0
- static/reddit-logo-youtube-png-favpng-Rukc5hsDFfci1sNk1LkFBccvW.jpeg +0 -0
- style.css +0 -28
- templates/error.html +22 -0
- templates/index.html +43 -0
- templates/src/__init__.py +0 -0
- templates/src/__pycache__/__init__.cpython-310.pyc +0 -0
- templates/src/__pycache__/reddit.cpython-310.pyc +0 -0
- templates/src/__pycache__/views.cpython-310.pyc +0 -0
- templates/src/reddit.py +58 -0
- templates/success.html +26 -0
index.html
DELETED
@@ -1,24 +0,0 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html>
|
3 |
-
<head>
|
4 |
-
<meta charset="utf-8" />
|
5 |
-
<meta name="viewport" content="width=device-width" />
|
6 |
-
<title>My static Space</title>
|
7 |
-
<link rel="stylesheet" href="style.css" />
|
8 |
-
</head>
|
9 |
-
<body>
|
10 |
-
<div class="card">
|
11 |
-
<h1>Welcome to your static Space!</h1>
|
12 |
-
<p>
|
13 |
-
You can modify this app directly by editing <i>index.html</i> in the
|
14 |
-
Files and versions tab.
|
15 |
-
</p>
|
16 |
-
<p>
|
17 |
-
Also don't forget to check the
|
18 |
-
<a href="https://huggingface.co/docs/hub/spaces" target="_blank"
|
19 |
-
>Spaces documentation</a
|
20 |
-
>.
|
21 |
-
</p>
|
22 |
-
</div>
|
23 |
-
</body>
|
24 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static/index.js
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
console.log('run')
|
static/reddit-logo-youtube-png-favpng-Rukc5hsDFfci1sNk1LkFBccvW.jpeg
ADDED
![]() |
style.css
DELETED
@@ -1,28 +0,0 @@
|
|
1 |
-
body {
|
2 |
-
padding: 2rem;
|
3 |
-
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
|
4 |
-
}
|
5 |
-
|
6 |
-
h1 {
|
7 |
-
font-size: 16px;
|
8 |
-
margin-top: 0;
|
9 |
-
}
|
10 |
-
|
11 |
-
p {
|
12 |
-
color: rgb(107, 114, 128);
|
13 |
-
font-size: 15px;
|
14 |
-
margin-bottom: 10px;
|
15 |
-
margin-top: 5px;
|
16 |
-
}
|
17 |
-
|
18 |
-
.card {
|
19 |
-
max-width: 620px;
|
20 |
-
margin: 0 auto;
|
21 |
-
padding: 16px;
|
22 |
-
border: 1px solid lightgray;
|
23 |
-
border-radius: 16px;
|
24 |
-
}
|
25 |
-
|
26 |
-
.card p:last-child {
|
27 |
-
margin-bottom: 0;
|
28 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
templates/error.html
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
8 |
+
<title>Reddit Topic Modelling</title>
|
9 |
+
</head>
|
10 |
+
<body style="background-color:#F2FAFB;">
|
11 |
+
<img align="right" src="static/reddit-logo-youtube-png-favpng-Rukc5hsDFfci1sNk1LkFBccvW.jpeg" alt="reddit-logo" style="width:90px;height:75px;">
|
12 |
+
|
13 |
+
<div class="container">
|
14 |
+
<h3>Error: {{ type_of_error }}</h3>
|
15 |
+
</div>
|
16 |
+
|
17 |
+
<script
|
18 |
+
type="'text/javascript"
|
19 |
+
src="{{ url_for('static', filename='index.js') }}">
|
20 |
+
</script>
|
21 |
+
</body>
|
22 |
+
</html>
|
templates/index.html
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
8 |
+
<title>Reddit Topic Modelling</title>
|
9 |
+
</head>
|
10 |
+
<body style="background-color:#F2FAFB;">
|
11 |
+
<img align="right" src="static/reddit-logo-youtube-png-favpng-Rukc5hsDFfci1sNk1LkFBccvW.jpeg" alt="reddit-logo" style="width:90px;height:75px;">
|
12 |
+
|
13 |
+
<div class="container">
|
14 |
+
|
15 |
+
<h1 align="center">Reddit Topic Modelling Tool</h1>
|
16 |
+
<form method='POST'>
|
17 |
+
<div class="form-group">
|
18 |
+
<label for="subreddit">Subreddit</label>
|
19 |
+
<input type="text" class="form-control" id="subreddit" name="subreddit" placeholder="Enter subreddit">
|
20 |
+
</div>
|
21 |
+
<div class="form-group">
|
22 |
+
<label for="amount">Select the number of subreddits (max 1000):</label>
|
23 |
+
<input type="text" class="form-control" id="amount" name="amount" placeholder="Enter amount of subreddits"/>
|
24 |
+
</div>
|
25 |
+
<br />
|
26 |
+
<div class="form-group">
|
27 |
+
<label for="type">Select the order:</label>
|
28 |
+
<select required id="type" name="type">
|
29 |
+
<option value="" disabled selected hidden></option>
|
30 |
+
<option value="new">new</option>
|
31 |
+
<option value="hot">hot</option>
|
32 |
+
<option value="top">top</option>
|
33 |
+
<option value="rising">rising</option>
|
34 |
+
</select>
|
35 |
+
</div>
|
36 |
+
<button type="submit" class="btn btn-primary">Submit</button>
|
37 |
+
</form>
|
38 |
+
<script
|
39 |
+
type="'text/javascript"
|
40 |
+
src="{{ url_for('static', filename='index.js') }}">
|
41 |
+
</script>
|
42 |
+
</body>
|
43 |
+
</html>
|
templates/src/__init__.py
ADDED
File without changes
|
templates/src/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (183 Bytes). View file
|
|
templates/src/__pycache__/reddit.cpython-310.pyc
ADDED
Binary file (1.81 kB). View file
|
|
templates/src/__pycache__/views.cpython-310.pyc
ADDED
Binary file (431 Bytes). View file
|
|
templates/src/reddit.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import praw
|
3 |
+
import logging
|
4 |
+
import pandas as pd
|
5 |
+
from typing import Generator
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
|
8 |
+
load_dotenv()
|
9 |
+
logger = logging.getLogger(__name__)
|
10 |
+
|
11 |
+
class RedditBot:
|
12 |
+
def __init__(
|
13 |
+
self,
|
14 |
+
client_id: str | None = None,
|
15 |
+
client_secret: str | None = None,
|
16 |
+
username: str | None = None,
|
17 |
+
password: str | None = None
|
18 |
+
) -> None:
|
19 |
+
|
20 |
+
self.reddit = praw.Reddit(
|
21 |
+
client_id = client_id if client_id else os.environ['REDDIT_CLIENT_ID'],
|
22 |
+
client_secret = client_secret if client_secret else os.environ['REDDIT_CLIENT_SECRET'],
|
23 |
+
username = username if username else os.environ['REDDIT_USERNAME'],
|
24 |
+
password = password if password else os.environ['REDDIT_PASSWORD'],
|
25 |
+
user_agent='bot'
|
26 |
+
)
|
27 |
+
|
28 |
+
def get_subreddits_posts(self, name: str, type: str, amount=100) -> Generator:
|
29 |
+
"""Gets the posts from a given subreddit"""
|
30 |
+
subreddit = self.reddit.subreddit(name)
|
31 |
+
if type == 'new':
|
32 |
+
posts = subreddit.new(limit=amount)
|
33 |
+
elif type == 'hot':
|
34 |
+
posts = subreddit.hot(limit=amount)
|
35 |
+
elif type == 'top':
|
36 |
+
posts = subreddit.top(limit=amount)
|
37 |
+
elif type == 'rising':
|
38 |
+
posts = subreddit.rising(limit=amount)
|
39 |
+
|
40 |
+
return posts
|
41 |
+
|
42 |
+
@staticmethod
|
43 |
+
def convert_posts_to_df(posts: Generator) -> pd.DataFrame:
|
44 |
+
"""Extracts the title and text from a post"""
|
45 |
+
df = pd.DataFrame(columns=['Title', 'Content'])
|
46 |
+
for n, p in enumerate(posts):
|
47 |
+
df.loc[n, 'Title'] = p.title
|
48 |
+
df.loc[n, 'Content'] = p.selftext
|
49 |
+
|
50 |
+
return df
|
51 |
+
|
52 |
+
def subreddit_exists(self, name: str) -> bool:
|
53 |
+
try:
|
54 |
+
self.reddit.subreddits.search_by_name(name, exact=True)
|
55 |
+
return True
|
56 |
+
except Exception as e:
|
57 |
+
logger.error(e)
|
58 |
+
return False
|
templates/success.html
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
8 |
+
<title>Reddit Topic Modelling</title>
|
9 |
+
</head>
|
10 |
+
<body style="background-color:#F2FAFB;">
|
11 |
+
<img align="right" src="static/reddit-logo-youtube-png-favpng-Rukc5hsDFfci1sNk1LkFBccvW.jpeg" alt="reddit-logo" style="width:90px;height:75px;">
|
12 |
+
|
13 |
+
<div class="container">
|
14 |
+
<h3>Downloading files:</h3>
|
15 |
+
<ul>
|
16 |
+
<li>topics.csv -> Topics information</li>
|
17 |
+
<li>docs_with_topics_info.csv -> Documents with topics information</li>
|
18 |
+
</ul>
|
19 |
+
</div>
|
20 |
+
|
21 |
+
<script
|
22 |
+
type="'text/javascript"
|
23 |
+
src="{{ url_for('static', filename='index.js') }}">
|
24 |
+
</script>
|
25 |
+
</body>
|
26 |
+
</html>
|