Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from newspaper import Article
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
# Load small LLM
|
| 6 |
+
reviewer = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 7 |
+
|
| 8 |
+
# Step 1: Extract blog content
|
| 9 |
+
def extract_text_from_url(url):
|
| 10 |
+
try:
|
| 11 |
+
article = Article(url)
|
| 12 |
+
article.download()
|
| 13 |
+
article.parse()
|
| 14 |
+
return article.text
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return f"Error: {e}"
|
| 17 |
+
|
| 18 |
+
# Step 2: Review content
|
| 19 |
+
def review_blog(text):
|
| 20 |
+
prompt = f"""Please review the following blog content. Fix grammar, crude/offensive language, or policy-violating parts. Suggest replacements:
|
| 21 |
+
|
| 22 |
+
{text}"""
|
| 23 |
+
result = reviewer(prompt, max_new_tokens=300)[0]['generated_text']
|
| 24 |
+
return result
|
| 25 |
+
|
| 26 |
+
# Step 3: Finalize after approval
|
| 27 |
+
def finalize_text(original_text, reviewed_suggestions):
|
| 28 |
+
# For simplicity, we'll just return reviewed version for now
|
| 29 |
+
# Later you can implement side-by-side diff + selective replacement
|
| 30 |
+
return reviewed_suggestions
|
| 31 |
+
|
| 32 |
+
# Gradio UI
|
| 33 |
+
with gr.Blocks() as app:
|
| 34 |
+
gr.Markdown("## 🧠 BlogChecker AI")
|
| 35 |
+
|
| 36 |
+
url = gr.Textbox(label="Enter Blog URL")
|
| 37 |
+
blog_content = gr.Textbox(label="Extracted Blog Text", lines=10)
|
| 38 |
+
reviewed = gr.Textbox(label="Suggested Revisions", lines=10)
|
| 39 |
+
final_output = gr.Textbox(label="Final Clean Blog", lines=10)
|
| 40 |
+
|
| 41 |
+
extract_btn = gr.Button("1️⃣ Extract Blog Text")
|
| 42 |
+
review_btn = gr.Button("2️⃣ Review Content")
|
| 43 |
+
approve_btn = gr.Button("3️⃣ Approve and Finalize")
|
| 44 |
+
|
| 45 |
+
extract_btn.click(fn=extract_text_from_url, inputs=url, outputs=blog_content)
|
| 46 |
+
review_btn.click(fn=review_blog, inputs=blog_content, outputs=reviewed)
|
| 47 |
+
approve_btn.click(fn=finalize_text, inputs=[blog_content, reviewed], outputs=final_output)
|
| 48 |
+
|
| 49 |
+
app.launch()
|