Update app.py
Browse files
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", "",
|
| 178 |
|
| 179 |
if not content.strip():
|
| 180 |
-
return "β Error: Please enter content to transform", "",
|
| 181 |
|
| 182 |
if len(content) > max_length:
|
| 183 |
-
return f"β Error: Content exceeds {max_length} characters limit", "",
|
| 184 |
|
| 185 |
model, error = self.setup_gemini(api_key)
|
| 186 |
if error:
|
| 187 |
-
return f"β {error}", "",
|
| 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", "",
|
| 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!
|
| 229 |
|
| 230 |
-
return success_msg, article_html,
|
| 231 |
|
| 232 |
except Exception as e:
|
| 233 |
-
return f"β Generation Error: {str(e)}", "",
|
| 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 &
|
| 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,
|
| 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
|