mroccuper commited on
Commit
ec9bea4
Β·
verified Β·
1 Parent(s): 74e9631

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -27
app.py CHANGED
@@ -174,17 +174,17 @@ Please transform the following content into a professional PR-style article:
174
  def generate_article(self, api_key, content, max_length=4000):
175
  """Generate PR-style article using Gemini API"""
176
  if not api_key.strip():
177
- return "❌ Error: Please enter your Gemini API key", "", 0.0, "", None
178
 
179
  if not content.strip():
180
- return "❌ Error: Please enter content to transform", "", 0.0, "", None
181
 
182
  if len(content) > max_length:
183
- return f"❌ Error: Content exceeds {max_length} characters limit", "", 0.0, "", None
184
 
185
  model, error = self.setup_gemini(api_key)
186
  if error:
187
- return f"❌ {error}", "", 0.0, "", None
188
 
189
  try:
190
  # Generate article
@@ -192,13 +192,10 @@ Please transform the following content into a professional PR-style article:
192
  response = model.generate_content(full_prompt)
193
 
194
  if not response.text:
195
- return "❌ Error: No response generated from API", "", 0.0, "", None
196
 
197
  article_html = response.text.strip()
198
 
199
- # Calculate readability score
200
- score, suggestions = self.calculate_readability_score(article_html)
201
-
202
  # Create downloadable file
203
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
204
  filename = f"pr_article_{timestamp}.html"
@@ -225,12 +222,12 @@ Please transform the following content into a professional PR-style article:
225
  </html>""")
226
  temp_file.close()
227
 
228
- success_msg = f"βœ… Article generated successfully! Readability Score: {score}/10"
229
 
230
- return success_msg, article_html, score, suggestions, temp_file.name
231
 
232
  except Exception as e:
233
- return f"❌ Generation Error: {str(e)}", "", 0.0, "", None
234
 
235
  def create_interface():
236
  generator = PRArticleGenerator()
@@ -293,7 +290,7 @@ def create_interface():
293
  )
294
 
295
  with gr.Column(scale=1):
296
- gr.HTML("<h3>πŸ“Š Output & Analysis</h3>")
297
 
298
  status_output = gr.Textbox(
299
  label="πŸ“‹ Status",
@@ -301,20 +298,6 @@ def create_interface():
301
  interactive=False
302
  )
303
 
304
- with gr.Row():
305
- score_output = gr.Number(
306
- label="πŸ“ˆ Readability Score",
307
- precision=1,
308
- interactive=False
309
- )
310
-
311
- suggestions_output = gr.Textbox(
312
- label="πŸ’‘ Improvement Suggestions",
313
- lines=8,
314
- interactive=False,
315
- placeholder="Suggestions will appear here..."
316
- )
317
-
318
  download_file = gr.File(
319
  label="πŸ“₯ Download HTML Article",
320
  interactive=False
@@ -332,7 +315,7 @@ def create_interface():
332
  generate_btn.click(
333
  fn=generator.generate_article,
334
  inputs=[api_key_input, content_input, max_length_slider],
335
- outputs=[status_output, article_output, score_output, suggestions_output, download_file]
336
  )
337
 
338
  # Add examples
 
174
  def generate_article(self, api_key, content, max_length=4000):
175
  """Generate PR-style article using Gemini API"""
176
  if not api_key.strip():
177
+ return "❌ Error: Please enter your Gemini API key", "", None
178
 
179
  if not content.strip():
180
+ return "❌ Error: Please enter content to transform", "", None
181
 
182
  if len(content) > max_length:
183
+ return f"❌ Error: Content exceeds {max_length} characters limit", "", None
184
 
185
  model, error = self.setup_gemini(api_key)
186
  if error:
187
+ return f"❌ {error}", "", None
188
 
189
  try:
190
  # Generate article
 
192
  response = model.generate_content(full_prompt)
193
 
194
  if not response.text:
195
+ return "❌ Error: No response generated from API", "", None
196
 
197
  article_html = response.text.strip()
198
 
 
 
 
199
  # Create downloadable file
200
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
201
  filename = f"pr_article_{timestamp}.html"
 
222
  </html>""")
223
  temp_file.close()
224
 
225
+ success_msg = f"βœ… Article generated successfully!"
226
 
227
+ return success_msg, article_html, temp_file.name
228
 
229
  except Exception as e:
230
+ return f"❌ Generation Error: {str(e)}", "", None
231
 
232
  def create_interface():
233
  generator = PRArticleGenerator()
 
290
  )
291
 
292
  with gr.Column(scale=1):
293
+ gr.HTML("<h3>πŸ“Š Output & Status</h3>")
294
 
295
  status_output = gr.Textbox(
296
  label="πŸ“‹ Status",
 
298
  interactive=False
299
  )
300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  download_file = gr.File(
302
  label="πŸ“₯ Download HTML Article",
303
  interactive=False
 
315
  generate_btn.click(
316
  fn=generator.generate_article,
317
  inputs=[api_key_input, content_input, max_length_slider],
318
+ outputs=[status_output, article_output, download_file]
319
  )
320
 
321
  # Add examples