Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,10 +3,10 @@ from transformers import pipeline
|
|
| 3 |
import PyPDF2
|
| 4 |
|
| 5 |
# ---------------- Load Hugging Face Pipelines ----------------
|
| 6 |
-
#
|
| 7 |
-
summarizer = pipeline("summarization", model="sshleifer/distilbart-
|
| 8 |
-
#
|
| 9 |
-
generator = pipeline("
|
| 10 |
|
| 11 |
# ---------------- Core Functions ----------------
|
| 12 |
def extract_text_from_pdf(pdf_file):
|
|
@@ -28,10 +28,10 @@ def eco_tips_generator(problem_keywords):
|
|
| 28 |
if not problem_keywords.strip():
|
| 29 |
return "Please enter some keywords (e.g., plastic, solar, energy saving)."
|
| 30 |
prompt = (
|
| 31 |
-
f"
|
| 32 |
-
f"
|
| 33 |
)
|
| 34 |
-
result = generator(prompt, max_length=
|
| 35 |
return result[0]["generated_text"]
|
| 36 |
|
| 37 |
def policy_summarization(pdf_file, policy_text):
|
|
@@ -48,8 +48,8 @@ def policy_summarization(pdf_file, policy_text):
|
|
| 48 |
try:
|
| 49 |
summary = summarizer(
|
| 50 |
text_to_summarize,
|
| 51 |
-
max_length=
|
| 52 |
-
min_length=
|
| 53 |
do_sample=False
|
| 54 |
)
|
| 55 |
return summary[0]['summary_text']
|
|
@@ -97,3 +97,4 @@ with gr.Blocks() as app:
|
|
| 97 |
# ---------------- Run App ----------------
|
| 98 |
if __name__ == "__main__":
|
| 99 |
app.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
| 3 |
import PyPDF2
|
| 4 |
|
| 5 |
# ---------------- Load Hugging Face Pipelines ----------------
|
| 6 |
+
# Lightweight summarizer
|
| 7 |
+
summarizer = pipeline("summarization", model="sshleifer/distilbart-xsum-12-6")
|
| 8 |
+
# Instruction-tuned generator for eco tips
|
| 9 |
+
generator = pipeline("text2text-generation", model="google/flan-t5-small")
|
| 10 |
|
| 11 |
# ---------------- Core Functions ----------------
|
| 12 |
def extract_text_from_pdf(pdf_file):
|
|
|
|
| 28 |
if not problem_keywords.strip():
|
| 29 |
return "Please enter some keywords (e.g., plastic, solar, energy saving)."
|
| 30 |
prompt = (
|
| 31 |
+
f"Give practical eco-friendly tips for sustainable living related to: {problem_keywords}. "
|
| 32 |
+
f"Provide specific, clear, and actionable solutions."
|
| 33 |
)
|
| 34 |
+
result = generator(prompt, max_length=150)
|
| 35 |
return result[0]["generated_text"]
|
| 36 |
|
| 37 |
def policy_summarization(pdf_file, policy_text):
|
|
|
|
| 48 |
try:
|
| 49 |
summary = summarizer(
|
| 50 |
text_to_summarize,
|
| 51 |
+
max_length=120,
|
| 52 |
+
min_length=30,
|
| 53 |
do_sample=False
|
| 54 |
)
|
| 55 |
return summary[0]['summary_text']
|
|
|
|
| 97 |
# ---------------- Run App ----------------
|
| 98 |
if __name__ == "__main__":
|
| 99 |
app.launch(server_name="0.0.0.0", server_port=7860)
|
| 100 |
+
|