chandrujobs commited on
Commit
ffd845b
·
verified ·
1 Parent(s): 2f388dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -15
app.py CHANGED
@@ -10,9 +10,6 @@ model_name = "gpt2"
10
  tokenizer = AutoTokenizer.from_pretrained(model_name)
11
  model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
12
 
13
- # Set pad_token_id to avoid errors
14
- model.config.pad_token_id = model.config.eos_token_id
15
-
16
  # NewsAPI Setup (Replace with your own API key)
17
  news_api_key = "35cbd14c45184a109fc2bbb5fff7fb1b" # Replace with your NewsAPI key
18
 
@@ -56,17 +53,7 @@ def generate_analysis(trending_topic):
56
 
57
  # Tokenize and generate text with a max limit on tokens
58
  inputs = tokenizer(input_text, return_tensors="pt").to(device)
59
-
60
- # Create a generation configuration
61
- generation_config = {
62
- "max_length": 80,
63
- "num_return_sequences": 1,
64
- "do_sample": True,
65
- "top_k": 50,
66
- "top_p": 0.95,
67
- }
68
-
69
- outputs = model.generate(**inputs, **generation_config)
70
 
71
  analysis = tokenizer.decode(outputs[0], skip_special_tokens=True)
72
 
@@ -102,6 +89,10 @@ def analyze_trends(page=1, page_size=9):
102
 
103
  # Gradio UI with 3 Columns Layout for Displaying News
104
  def display_news_cards(page=1, page_size=9):
 
 
 
 
105
  analysis_results = analyze_trends(page=page, page_size=page_size)
106
  current_date = datetime.now().strftime("%d-%m-%Y") # Format: DD-MM-YYYY
107
 
@@ -150,4 +141,4 @@ def gradio_interface():
150
 
151
  # Launch the Gradio UI
152
  if __name__ == "__main__":
153
- gradio_interface().launch() # Removed share=True since it is not supported
 
10
  tokenizer = AutoTokenizer.from_pretrained(model_name)
11
  model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
12
 
 
 
 
13
  # NewsAPI Setup (Replace with your own API key)
14
  news_api_key = "35cbd14c45184a109fc2bbb5fff7fb1b" # Replace with your NewsAPI key
15
 
 
53
 
54
  # Tokenize and generate text with a max limit on tokens
55
  inputs = tokenizer(input_text, return_tensors="pt").to(device)
56
+ outputs = model.generate(**inputs, max_length=80, num_return_sequences=1, do_sample=True, top_k=50, top_p=0.95)
 
 
 
 
 
 
 
 
 
 
57
 
58
  analysis = tokenizer.decode(outputs[0], skip_special_tokens=True)
59
 
 
89
 
90
  # Gradio UI with 3 Columns Layout for Displaying News
91
  def display_news_cards(page=1, page_size=9):
92
+ # Show loading message first
93
+ loading_message = "Please wait while we fetch the latest news..."
94
+
95
+ # Fetch analysis results
96
  analysis_results = analyze_trends(page=page, page_size=page_size)
97
  current_date = datetime.now().strftime("%d-%m-%Y") # Format: DD-MM-YYYY
98
 
 
141
 
142
  # Launch the Gradio UI
143
  if __name__ == "__main__":
144
+ gradio_interface().launch(share=True) # Launch with share=True to allow public access