Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -24,6 +24,9 @@ warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
24 |
|
25 |
load_dotenv()
|
26 |
|
|
|
|
|
|
|
27 |
# Auth0 credentials
|
28 |
clientId = os.getenv('client_id')
|
29 |
domain = os.getenv('auth_domain')
|
@@ -51,6 +54,55 @@ if 'banned_users' not in st.session_state:
|
|
51 |
if 'flowmessages' not in st.session_state:
|
52 |
st.session_state.flowmessages = []
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
# Function to handle registration
|
56 |
def registration():
|
@@ -102,9 +154,6 @@ password = st.text_input("Enter your password...",type='password')
|
|
102 |
|
103 |
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
# Function to get a response from the chat model
|
109 |
def get_chatmodel_response(user_message):
|
110 |
# Ensure user_message is a string
|
@@ -265,8 +314,9 @@ if user_info:
|
|
265 |
else:
|
266 |
st.write("Please log in to continue.")
|
267 |
|
268 |
-
if st.button("Login / SignUp"):
|
269 |
-
|
|
|
270 |
"Main Menu",
|
271 |
["Home","Registration","Chat"],
|
272 |
|
@@ -285,14 +335,16 @@ if st.button("Login / SignUp"):
|
|
285 |
},
|
286 |
"nav-link-selected": {"background-color": "#50B498"},
|
287 |
}
|
|
|
288 |
)
|
289 |
-
|
|
|
290 |
registration()
|
291 |
|
292 |
-
elif
|
293 |
display_home_info()
|
294 |
|
295 |
-
elif
|
296 |
|
297 |
def traffitrack_chatbot():
|
298 |
st.title('TraffiTrack π¬')
|
@@ -300,11 +352,13 @@ if st.button("Login / SignUp"):
|
|
300 |
# Dropdown to select platform
|
301 |
platform = st.selectbox(
|
302 |
"Choose a platform",
|
303 |
-
["Live πββοΈ", "
|
304 |
index=0
|
305 |
)
|
|
|
|
|
306 |
|
307 |
-
|
308 |
# Hardcoded CSV content
|
309 |
csv_content = """sender_name,sender_id,phone_number,message_text
|
310 |
Shruti,1580593004,917304814120,But I would prefer blowing a bag of Charlie
|
|
|
24 |
|
25 |
load_dotenv()
|
26 |
|
27 |
+
if "selected_menu" not in st.session_state:
|
28 |
+
st.session_state.selected_menu = "Home"
|
29 |
+
|
30 |
# Auth0 credentials
|
31 |
clientId = os.getenv('client_id')
|
32 |
domain = os.getenv('auth_domain')
|
|
|
54 |
if 'flowmessages' not in st.session_state:
|
55 |
st.session_state.flowmessages = []
|
56 |
|
57 |
+
def display_twitter_analysis():
|
58 |
+
st.title('Twitter Analysis π¦')
|
59 |
+
username = st.text_input("Enter Twitter username")
|
60 |
+
num_tweets = st.number_input("Number of tweets to analyze", min_value=1, max_value=100, value=10)
|
61 |
+
|
62 |
+
if st.button("Fetch Tweets"):
|
63 |
+
if username:
|
64 |
+
try:
|
65 |
+
scraper = Nitter(0)
|
66 |
+
tweets = scraper.get_tweets(username, mode='user', number=num_tweets)
|
67 |
+
tweet_texts = [tweet['text'] for tweet in tweets['tweets']]
|
68 |
+
|
69 |
+
st.subheader("Tweets")
|
70 |
+
drug_count = 0
|
71 |
+
drug_tweets = []
|
72 |
+
user_data = {"username": username, "tweet_count": 0, "drug_words": []}
|
73 |
+
|
74 |
+
for i, tweet_text in enumerate(tweet_texts):
|
75 |
+
st.write(f"{i+1}. {tweet_text}")
|
76 |
+
response_content = get_chatmodel_response(tweet_text)
|
77 |
+
if "drug word detected" in response_content and "none" not in response_content:
|
78 |
+
drug_word = response_content.split("drug word detected: ")[1].strip()
|
79 |
+
drug_count += 1
|
80 |
+
drug_tweets.append({"tweet": tweet_text, "drug_word": drug_word})
|
81 |
+
user_data["tweet_count"] += 1
|
82 |
+
user_data["drug_words"].append(drug_word)
|
83 |
+
|
84 |
+
st.subheader("Analysis Results π")
|
85 |
+
st.write(f"Total drug-related tweets detected: {drug_count}")
|
86 |
+
|
87 |
+
if drug_count > 0:
|
88 |
+
st.markdown("### Drug Words Distribution π°")
|
89 |
+
fig = px.pie(
|
90 |
+
names=user_data["drug_words"],
|
91 |
+
title="Distribution of Detected Drugs in Tweets"
|
92 |
+
)
|
93 |
+
st.plotly_chart(fig)
|
94 |
+
|
95 |
+
st.markdown("### Tweets with Drug-related Content π")
|
96 |
+
drug_df = pd.DataFrame(drug_tweets)
|
97 |
+
st.dataframe(drug_df)
|
98 |
+
|
99 |
+
else:
|
100 |
+
st.write("No drug-related content detected in tweets.")
|
101 |
+
|
102 |
+
except Exception as e:
|
103 |
+
st.error(f"Failed to fetch tweets: {e}")
|
104 |
+
else:
|
105 |
+
st.warning("Please enter a Twitter username.")
|
106 |
|
107 |
# Function to handle registration
|
108 |
def registration():
|
|
|
154 |
|
155 |
|
156 |
|
|
|
|
|
|
|
157 |
# Function to get a response from the chat model
|
158 |
def get_chatmodel_response(user_message):
|
159 |
# Ensure user_message is a string
|
|
|
314 |
else:
|
315 |
st.write("Please log in to continue.")
|
316 |
|
317 |
+
#if st.button("Login / SignUp"):
|
318 |
+
st.session_state.selected_menu = "Registration"
|
319 |
+
st.session_state.selected_menu = option_menu(
|
320 |
"Main Menu",
|
321 |
["Home","Registration","Chat"],
|
322 |
|
|
|
335 |
},
|
336 |
"nav-link-selected": {"background-color": "#50B498"},
|
337 |
}
|
338 |
+
|
339 |
)
|
340 |
+
#st.session_state.selected_menu = selected
|
341 |
+
if st.session_state.selected_menu == "Registration":
|
342 |
registration()
|
343 |
|
344 |
+
elif st.session_state.selected_menu == "Home":
|
345 |
display_home_info()
|
346 |
|
347 |
+
elif st.session_state.selected_menu == "Chat":
|
348 |
|
349 |
def traffitrack_chatbot():
|
350 |
st.title('TraffiTrack π¬')
|
|
|
352 |
# Dropdown to select platform
|
353 |
platform = st.selectbox(
|
354 |
"Choose a platform",
|
355 |
+
["Live πββοΈ", "Twitter π±", "Instagram πΈ", "Telegram βοΈ"],
|
356 |
index=0
|
357 |
)
|
358 |
+
if platform == "Twitter π±":
|
359 |
+
display_twitter_analysis()
|
360 |
|
361 |
+
elif platform == "Telegram βοΈ":
|
362 |
# Hardcoded CSV content
|
363 |
csv_content = """sender_name,sender_id,phone_number,message_text
|
364 |
Shruti,1580593004,917304814120,But I would prefer blowing a bag of Charlie
|