Update app.py
Browse files
app.py
CHANGED
|
@@ -49,6 +49,7 @@ Mimic top-tier PR publications using this structure:
|
|
| 49 |
- Bullet lists for portfolio highlights or key achievements.
|
| 50 |
- Insert **1 vision-driven quote** (real or fictional) if none provided.
|
| 51 |
- Ready to paste into any CMS or press distribution tool.
|
|
|
|
| 52 |
|
| 53 |
π₯ INPUT FORMAT:
|
| 54 |
User may provide raw facts, a bio, a business update, or a rough news draft.
|
|
@@ -59,10 +60,26 @@ User may provide raw facts, a bio, a business update, or a rough news draft.
|
|
| 59 |
- β
Meta Title
|
| 60 |
- β
Meta Description
|
| 61 |
- β
Target Keyword
|
|
|
|
| 62 |
|
| 63 |
Please transform the following content into a professional PR-style article:
|
| 64 |
"""
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
def setup_gemini(self, api_key):
|
| 67 |
"""Configure Gemini API"""
|
| 68 |
try:
|
|
@@ -189,7 +206,8 @@ Please transform the following content into a professional PR-style article:
|
|
| 189 |
if not response.text:
|
| 190 |
return "β Error: No response generated from API", "", None
|
| 191 |
|
| 192 |
-
|
|
|
|
| 193 |
|
| 194 |
# Create downloadable file
|
| 195 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
@@ -315,7 +333,7 @@ def create_interface():
|
|
| 315 |
|
| 316 |
# Add examples
|
| 317 |
gr.HTML("""
|
| 318 |
-
<div style="margin-top: 30px; padding: 20px;
|
| 319 |
<h3>π‘ Example Input Content:</h3>
|
| 320 |
<p><strong>Business Acquisition:</strong> "Tech entrepreneur John Smith announced the acquisition of downtown office building for $15M. Smith, who previously founded two successful startups, plans to convert the space into a modern co-working hub."</p>
|
| 321 |
<p><strong>Product Launch:</strong> "AI company releases new software that reduces processing time by 60%. The tool has been tested by 500+ businesses with positive results."</p>
|
|
@@ -335,9 +353,4 @@ if __name__ == "__main__":
|
|
| 335 |
os.system("pip install google-generativeai textstat")
|
| 336 |
|
| 337 |
app = create_interface()
|
| 338 |
-
app.launch(
|
| 339 |
-
server_name="0.0.0.0",
|
| 340 |
-
server_port=7860,
|
| 341 |
-
share=True,
|
| 342 |
-
show_error=True
|
| 343 |
-
)
|
|
|
|
| 49 |
- Bullet lists for portfolio highlights or key achievements.
|
| 50 |
- Insert **1 vision-driven quote** (real or fictional) if none provided.
|
| 51 |
- Ready to paste into any CMS or press distribution tool.
|
| 52 |
+
- Return ONLY the HTML content without any markdown code blocks or backticks.
|
| 53 |
|
| 54 |
π₯ INPUT FORMAT:
|
| 55 |
User may provide raw facts, a bio, a business update, or a rough news draft.
|
|
|
|
| 60 |
- β
Meta Title
|
| 61 |
- β
Meta Description
|
| 62 |
- β
Target Keyword
|
| 63 |
+
- Do NOT wrap the output in ```html or ``` markdown blocks.
|
| 64 |
|
| 65 |
Please transform the following content into a professional PR-style article:
|
| 66 |
"""
|
| 67 |
|
| 68 |
+
def clean_html_output(self, text):
|
| 69 |
+
"""Remove markdown code blocks and clean HTML output"""
|
| 70 |
+
# Remove markdown code blocks (```html, ```HTML, ```, etc.)
|
| 71 |
+
cleaned = re.sub(r'```[a-zA-Z]*\n?', '', text)
|
| 72 |
+
cleaned = re.sub(r'\n?```', '', cleaned)
|
| 73 |
+
|
| 74 |
+
# Remove any remaining backticks at start/end
|
| 75 |
+
cleaned = cleaned.strip('`')
|
| 76 |
+
|
| 77 |
+
# Clean up extra whitespace
|
| 78 |
+
cleaned = re.sub(r'\n{3,}', '\n\n', cleaned)
|
| 79 |
+
cleaned = cleaned.strip()
|
| 80 |
+
|
| 81 |
+
return cleaned
|
| 82 |
+
|
| 83 |
def setup_gemini(self, api_key):
|
| 84 |
"""Configure Gemini API"""
|
| 85 |
try:
|
|
|
|
| 206 |
if not response.text:
|
| 207 |
return "β Error: No response generated from API", "", None
|
| 208 |
|
| 209 |
+
# Clean the HTML output to remove markdown code blocks
|
| 210 |
+
article_html = self.clean_html_output(response.text.strip())
|
| 211 |
|
| 212 |
# Create downloadable file
|
| 213 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
|
| 333 |
|
| 334 |
# Add examples
|
| 335 |
gr.HTML("""
|
| 336 |
+
<div style="margin-top: 30px; padding: 20px; border-radius: 10px;">
|
| 337 |
<h3>π‘ Example Input Content:</h3>
|
| 338 |
<p><strong>Business Acquisition:</strong> "Tech entrepreneur John Smith announced the acquisition of downtown office building for $15M. Smith, who previously founded two successful startups, plans to convert the space into a modern co-working hub."</p>
|
| 339 |
<p><strong>Product Launch:</strong> "AI company releases new software that reduces processing time by 60%. The tool has been tested by 500+ businesses with positive results."</p>
|
|
|
|
| 353 |
os.system("pip install google-generativeai textstat")
|
| 354 |
|
| 355 |
app = create_interface()
|
| 356 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|