Manasa1 commited on
Commit
f61d1a4
·
verified ·
1 Parent(s): 7367aa3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  import os
 
3
  from tweet_analyzer import TweetDatasetProcessor
4
  from dotenv import load_dotenv
5
 
@@ -31,7 +32,28 @@ class TwitterCloneApp:
31
  return "Please upload and analyze a dataset first."
32
 
33
  try:
34
- tweet = self.processor.generate_tweet(context)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  return tweet
36
  except Exception as e:
37
  return f"Error generating tweet: {str(e)}"
@@ -74,3 +96,4 @@ def main():
74
  if __name__ == "__main__":
75
  main()
76
 
 
 
1
  import gradio as gr
2
  import os
3
+ import random
4
  from tweet_analyzer import TweetDatasetProcessor
5
  from dotenv import load_dotenv
6
 
 
32
  return "Please upload and analyze a dataset first."
33
 
34
  try:
35
+ # Predefined contexts
36
+ additional_contexts = [
37
+ "Comment on a recent technological advancement.",
38
+ "Share a motivational thought.",
39
+ "Discuss a current trending topic.",
40
+ "Reflect on a past experience.",
41
+ "Provide advice to followers."
42
+ ]
43
+
44
+ # Extract historical topics
45
+ historical_topics = self.processor.analyze_topics(n_topics=5)
46
+
47
+ # Combine predefined contexts with historical topics
48
+ combined_contexts = additional_contexts + historical_topics
49
+ selected_contexts = random.sample(combined_contexts, min(3, len(combined_contexts)))
50
+
51
+ # If user provided context, add it to the mix
52
+ if context:
53
+ selected_contexts.append(context)
54
+
55
+ # Generate the tweet with diverse contexts
56
+ tweet = self.processor.generate_tweet(context=" | ".join(selected_contexts))
57
  return tweet
58
  except Exception as e:
59
  return f"Error generating tweet: {str(e)}"
 
96
  if __name__ == "__main__":
97
  main()
98
 
99
+