Refat81 commited on
Commit
5850777
Β·
verified Β·
1 Parent(s): cbd7280

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -238
app.py CHANGED
@@ -1,238 +1,100 @@
1
- # main_dashboard.py
2
- import streamlit as st
3
- import subprocess
4
- import sys
5
- import os
6
- import webbrowser
7
- import time
8
- import threading
9
-
10
- def check_port_in_use(port: int) -> bool:
11
- import socket
12
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
13
- s.settimeout(1)
14
- return s.connect_ex(('localhost', port)) == 0
15
-
16
- def get_available_port(start_port: int = 8601) -> int:
17
- port = start_port
18
- while check_port_in_use(port):
19
- port += 1
20
- return port
21
-
22
- def run_streamlit_app_in_thread(app_file: str, port: int):
23
- def run_app():
24
- try:
25
- subprocess.run([
26
- sys.executable, "-m", "streamlit", "run",
27
- app_file,
28
- "--server.port", str(port),
29
- "--server.headless", "true",
30
- "--browser.serverAddress", "localhost"
31
- ], check=True)
32
- except subprocess.CalledProcessError as e:
33
- print(f"Error running {app_file}: {e}")
34
-
35
- thread = threading.Thread(target=run_app, daemon=True)
36
- thread.start()
37
- return thread
38
-
39
- def main():
40
- st.set_page_config(
41
- page_title="Social Media Data Extractor",
42
- page_icon="πŸ”",
43
- layout="wide",
44
- initial_sidebar_state="expanded"
45
- )
46
-
47
- st.markdown("""
48
- <style>
49
- .stApp { background-color: #0e1117; color: white; }
50
- .main-header { background: linear-gradient(135deg, #1a2a6c, #b21f1f); color: white; padding: 2rem; border-radius: 10px; text-align: center; margin-bottom: 2rem; }
51
- .platform-card { background-color: #262730; padding: 1.5rem; border-radius: 10px; border-left: 4px solid; margin: 1rem 0; height: 280px; }
52
- .linkedin-card { border-left-color: #0077B5; }
53
- .facebook-card { border-left-color: #1877F2; }
54
- .facebook-pro-card { border-left-color: #FF6B35; }
55
- .feature-list { margin: 1rem 0; padding-left: 1.5rem; flex-grow: 1; }
56
- .api-key-section { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 1.5rem; border-radius: 10px; margin-bottom: 2rem; }
57
- .status-box { background-color: #1a1a2e; padding: 1rem; border-radius: 5px; margin: 0.5rem 0; min-height: 120px; }
58
- </style>
59
- """, unsafe_allow_html=True)
60
-
61
- # API Key Section
62
- st.markdown("""
63
- <div class="api-key-section">
64
- <h2 style="margin:0; color:white;">πŸ”‘ HuggingFace API Key Required</h2>
65
- <p style="margin:0; color:white; opacity:0.9;">Get FREE API key from: <a href="https://huggingface.co/settings/tokens" target="_blank" style="color:white; text-decoration:underline;">huggingface.co/settings/tokens</a></p>
66
- </div>
67
- """, unsafe_allow_html=True)
68
-
69
- # API Configuration
70
- hf_api_key = st.text_input(
71
- "πŸ€— Enter Your HuggingFace API Key",
72
- type="password",
73
- placeholder="hf_xxxxxxxxxxxxxxxx",
74
- help="Get FREE API key from huggingface.co/settings/tokens"
75
- )
76
-
77
- # Store API key
78
- if hf_api_key:
79
- st.session_state.hf_api_key = hf_api_key
80
- st.success("βœ… HuggingFace API Key saved! You can now launch extractors.")
81
-
82
- # Header
83
- st.markdown("""
84
- <div class="main-header">
85
- <h1 style="margin:0;">πŸ” Social Media Data Extractor</h1>
86
- <p style="margin:0; opacity: 0.9;">100% Free - No Local Setup Required</p>
87
- </div>
88
- """, unsafe_allow_html=True)
89
-
90
- # Initialize session state
91
- if 'linkedin_port' not in st.session_state:
92
- st.session_state.linkedin_port = None
93
- if 'facebook_port' not in st.session_state:
94
- st.session_state.facebook_port = None
95
- if 'facebook_pro_port' not in st.session_state:
96
- st.session_state.facebook_pro_port = None
97
-
98
- # Platform selection
99
- st.markdown("## πŸš€ Launch Extractors")
100
-
101
- col1, col2, col3 = st.columns(3)
102
-
103
- with col1:
104
- st.markdown("""
105
- <div class="platform-card linkedin-card">
106
- <h3>πŸ’Ό LinkedIn Extractor</h3>
107
- <ul class="feature-list">
108
- <li>No login required</li>
109
- <li>Profile, company, and post analysis</li>
110
- <li>Quick data extraction</li>
111
- <li>AI-powered insights</li>
112
- <li>100% Free</li>
113
- </ul>
114
- </div>
115
- """, unsafe_allow_html=True)
116
-
117
- if st.button("πŸš€ Launch LinkedIn Extractor", key="linkedin_btn", use_container_width=True):
118
- if not st.session_state.get('hf_api_key'):
119
- st.error("❌ Please enter your HuggingFace API Key first")
120
- else:
121
- if os.path.exists("linkdin_deploy.py"):
122
- port = get_available_port(8601)
123
- st.session_state.linkedin_port = port
124
- with st.spinner(f"Starting LinkedIn extractor..."):
125
- run_streamlit_app_in_thread("linkdin_deploy.py", port)
126
- time.sleep(3)
127
- webbrowser.open_new_tab(f"http://localhost:{port}")
128
- st.success(f"βœ… LinkedIn extractor launched!")
129
- else:
130
- st.error("❌ linkdin_deploy.py file not found!")
131
-
132
- with col2:
133
- st.markdown("""
134
- <div class="platform-card facebook-card">
135
- <h3>πŸ“˜ Facebook Extractor</h3>
136
- <ul class="feature-list">
137
- <li>Manual login required</li>
138
- <li>Group post extraction</li>
139
- <li>Works with private groups</li>
140
- <li>AI conversation analysis</li>
141
- <li>100% Free</li>
142
- </ul>
143
- </div>
144
- """, unsafe_allow_html=True)
145
-
146
- if st.button("πŸš€ Launch Facebook Extractor", key="facebook_btn", use_container_width=True):
147
- if not st.session_state.get('hf_api_key'):
148
- st.error("❌ Please enter your HuggingFace API Key first")
149
- else:
150
- if os.path.exists("facebook_deploy.py"):
151
- port = get_available_port(8701)
152
- st.session_state.facebook_port = port
153
- with st.spinner(f"Starting Facebook extractor..."):
154
- run_streamlit_app_in_thread("facebook_deploy.py", port)
155
- time.sleep(3)
156
- webbrowser.open_new_tab(f"http://localhost:{port}")
157
- st.success(f"βœ… Facebook extractor launched!")
158
- else:
159
- st.error("❌ facebook_deploy.py file not found!")
160
-
161
- with col3:
162
- st.markdown("""
163
- <div class="platform-card facebook-pro-card">
164
- <h3>πŸ”₯ Facebook Extractor 2.0</h3>
165
- <ul class="feature-list">
166
- <li>Enhanced Facebook data extraction</li>
167
- <li>More powerful algorithms</li>
168
- <li>Faster processing speed</li>
169
- <li>Advanced AI analysis</li>
170
- <li>100% Free</li>
171
- </ul>
172
- </div>
173
- """, unsafe_allow_html=True)
174
-
175
- if st.button("πŸš€ Launch Facebook Extractor 2.0", key="facebook_pro_btn", use_container_width=True):
176
- if not st.session_state.get('hf_api_key'):
177
- st.error("❌ Please enter your HuggingFace API Key first")
178
- else:
179
- if os.path.exists("let_deploy.py"):
180
- port = get_available_port(8801)
181
- st.session_state.facebook_pro_port = port
182
- with st.spinner(f"Starting Facebook Extractor 2.0..."):
183
- run_streamlit_app_in_thread("let_deploy.py", port)
184
- time.sleep(3)
185
- webbrowser.open_new_tab(f"http://localhost:{port}")
186
- st.success(f"βœ… Facebook Extractor 2.0 launched!")
187
- else:
188
- st.error("❌ let_deploy.py file not found!")
189
-
190
- # Status
191
- st.markdown("---")
192
- st.subheader("πŸ”„ Current Status")
193
-
194
- status_col1, status_col2, status_col3 = st.columns(3)
195
-
196
- with status_col1:
197
- st.markdown("### πŸ’Ό LinkedIn")
198
- if st.session_state.linkedin_port:
199
- st.success(f"βœ… Running on port {st.session_state.linkedin_port}")
200
- else:
201
- st.info("πŸ’€ Not running")
202
-
203
- with status_col2:
204
- st.markdown("### πŸ“˜ Facebook")
205
- if st.session_state.facebook_port:
206
- st.success(f"βœ… Running on port {st.session_state.facebook_port}")
207
- else:
208
- st.info("πŸ’€ Not running")
209
-
210
- with status_col3:
211
- st.markdown("### πŸ”₯ Facebook 2.0")
212
- if st.session_state.facebook_pro_port:
213
- st.success(f"βœ… Running on port {st.session_state.facebook_pro_port}")
214
- else:
215
- st.info("πŸ’€ Not running")
216
-
217
- # Instructions
218
- with st.expander("πŸ“‹ How to Use", expanded=True):
219
- st.markdown("""
220
- 1. **Get FREE API Key:**
221
- - Go to https://huggingface.co/settings/tokens
222
- - Create account (FREE)
223
- - Click "New token"
224
- - Copy your token (starts with hf_)
225
-
226
- 2. **Enter API Key above**
227
-
228
- 3. **Click any extractor to launch**
229
-
230
- 4. **For Streamlit Cloud:**
231
- - Add this to Secrets:
232
- ```
233
- HUGGINGFACEHUB_API_TOKEN = "your_token_here"
234
- ```
235
- """)
236
-
237
- if __name__ == "__main__":
238
- main()
 
1
+ # main_dashboard.py
2
+ import streamlit as st
3
+ import os
4
+
5
+ def main():
6
+ st.set_page_config(
7
+ page_title="Social Media Data Extractor",
8
+ page_icon="πŸ”",
9
+ layout="wide",
10
+ initial_sidebar_state="expanded"
11
+ )
12
+
13
+ st.markdown("""
14
+ <style>
15
+ .stApp { background-color: #0e1117; color: white; }
16
+ .main-header { background: linear-gradient(135deg, #1a2a6c, #b21f1f); color: white; padding: 2rem; border-radius: 10px; text-align: center; margin-bottom: 2rem; }
17
+ .platform-card { background-color: #262730; padding: 1.5rem; border-radius: 10px; border-left: 4px solid; margin: 1rem 0; height: 280px; }
18
+ .linkedin-card { border-left-color: #0077B5; }
19
+ .facebook-card { border-left-color: #1877F2; }
20
+ .facebook-pro-card { border-left-color: #FF6B35; }
21
+ .feature-list { margin: 1rem 0; padding-left: 1.5rem; flex-grow: 1; }
22
+ .api-key-section { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 1.5rem; border-radius: 10px; margin-bottom: 2rem; }
23
+ </style>
24
+ """, unsafe_allow_html=True)
25
+
26
+ # Header
27
+ st.markdown("""
28
+ <div class="main-header">
29
+ <h1 style="margin:0;">πŸ” Social Media Data Extractor</h1>
30
+ <p style="margin:0; opacity: 0.9;">100% Free - No Local Setup Required</p>
31
+ </div>
32
+ """, unsafe_allow_html=True)
33
+
34
+ # Platform selection
35
+ st.markdown("## πŸš€ Launch Extractors")
36
+
37
+ col1, col2, col3 = st.columns(3)
38
+
39
+ with col1:
40
+ st.markdown("""
41
+ <div class="platform-card linkedin-card">
42
+ <h3>πŸ’Ό LinkedIn Extractor</h3>
43
+ <ul class="feature-list">
44
+ <li>No login required</li>
45
+ <li>Profile, company, and post analysis</li>
46
+ <li>Quick data extraction</li>
47
+ <li>AI-powered insights</li>
48
+ <li>100% Free</li>
49
+ </ul>
50
+ </div>
51
+ """, unsafe_allow_html=True)
52
+
53
+ if st.button("πŸš€ Launch LinkedIn Extractor", key="linkedin_btn", use_container_width=True):
54
+ st.switch_page("pages/linkedin_extractor.py")
55
+
56
+ with col2:
57
+ st.markdown("""
58
+ <div class="platform-card facebook-card">
59
+ <h3>πŸ“˜ Facebook Extractor</h3>
60
+ <ul class="feature-list">
61
+ <li>Manual login required</li>
62
+ <li>Group post extraction</li>
63
+ <li>Works with private groups</li>
64
+ <li>AI conversation analysis</li>
65
+ <li>100% Free</li>
66
+ </ul>
67
+ </div>
68
+ """, unsafe_allow_html=True)
69
+
70
+ if st.button("πŸš€ Launch Facebook Extractor", key="facebook_btn", use_container_width=True):
71
+ st.switch_page("pages/facebook_extractor.py")
72
+
73
+ with col3:
74
+ st.markdown("""
75
+ <div class="platform-card facebook-pro-card">
76
+ <h3>πŸ”₯ Facebook Extractor 2.0</h3>
77
+ <ul class="feature-list">
78
+ <li>Enhanced Facebook data extraction</li>
79
+ <li>More powerful algorithms</li>
80
+ <li>Faster processing speed</li>
81
+ <li>Advanced AI analysis</li>
82
+ <li>100% Free</li>
83
+ </ul>
84
+ </div>
85
+ """, unsafe_allow_html=True)
86
+
87
+ if st.button("πŸš€ Launch Facebook Extractor 2.0", key="facebook_pro_btn", use_container_width=True):
88
+ st.switch_page("pages/facebook_extractor_pro.py")
89
+
90
+ # Instructions
91
+ with st.expander("πŸ“‹ How to Use", expanded=True):
92
+ st.markdown("""
93
+ 1. **Click any extractor to launch**
94
+ 2. **For LinkedIn:** Enter any LinkedIn URL
95
+ 3. **For Facebook:** Manual login required for private groups
96
+ 4. **AI Analysis:** Chat with extracted data
97
+ """)
98
+
99
+ if __name__ == "__main__":
100
+ main()