fw1zr commited on
Commit
64e5941
1 Parent(s): 9e0716c

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: IYC Instagram Scraping Tool
3
- emoji: 👁
4
- colorFrom: purple
5
- colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 4.19.2
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: IYC_instagram_scraping_tool
3
+ app_file: webapp.py
 
 
4
  sdk: gradio
5
+ sdk_version: 4.3.0
 
 
6
  ---
 
 
__pycache__/app.cpython-311.pyc ADDED
Binary file (726 Bytes). View file
 
__pycache__/utils.cpython-311.pyc ADDED
Binary file (2.38 kB). View file
 
utils.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import requests
3
+
4
+
5
+
6
+ def extract_instagram_code(url: str) -> str:
7
+ parts = list(filter(None, url.split('/')))
8
+ return parts[-1]
9
+
10
+
11
+ def get_users_from_keyword(keyword: str):
12
+ import requests
13
+
14
+ url = f"https://api.instagapi.com/searchuser/{keyword}"
15
+
16
+ headers = {
17
+ "X-InstagAPI-Key": "ec4fe09e395935a8df1a3228ead80655"
18
+ }
19
+
20
+ response = requests.get(url, headers=headers)
21
+
22
+ data = []
23
+ for user in response.json()['data']:
24
+ user = user['user']
25
+ data.append({
26
+ "username": user['username'],
27
+ 'is_verified': user['is_verified']
28
+ })
29
+
30
+ df = pd.DataFrame(data)
31
+ return df
32
+
33
+ def get_comments(url: str):
34
+ shortcode = extract_instagram_code(url)
35
+ url = f"https://api.instagapi.com/postcomments/{shortcode}/"
36
+
37
+ headers = {
38
+ "X-InstagAPI-Key": "ec4fe09e395935a8df1a3228ead80655"
39
+ }
40
+
41
+ response = requests.get(url, headers=headers)
42
+
43
+
44
+ data = []
45
+ for comment in response.json()['data']['comments']:
46
+ data.append({
47
+ "username": comment['user']['username'],
48
+ "comment_text": comment['text'],
49
+ "user_is_verified": comment['user']['is_verified'],
50
+ "user_is_private": comment['user']['is_private'],
51
+ "comment_like_count": comment['comment_like_count'] # Assuming this is the correct key
52
+
53
+
54
+ })
55
+
56
+ df = pd.DataFrame(data)
57
+ return df
58
+
webapp.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from utils import get_comments, get_users_from_keyword
3
+
4
+ iface1 = gr.Interface(fn=get_comments,
5
+ inputs=gr.Textbox(label="Instagram Post URL"),
6
+ outputs=gr.Dataframe(),
7
+ title="Instagram Comments Extractor",
8
+ description="Enter an Instagram post URL to extract and display comments.")
9
+
10
+
11
+ iface2 = gr.Interface(fn=get_users_from_keyword,
12
+ inputs=gr.Textbox(label="Search keyword"),
13
+ outputs=gr.Dataframe(),
14
+ title="Instagram User keyword search",
15
+ description="Enter an keyword to search for users.")
16
+
17
+ demo = gr.TabbedInterface([iface1, iface2], ["Instagram comment extractor", "Instagram user keyword search"])
18
+
19
+ demo.launch(share=True)