rathil123 commited on
Commit
6a69b65
·
verified ·
1 Parent(s): 3e4c3ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -3,10 +3,10 @@ from transformers import pipeline
3
  import PyPDF2
4
 
5
  # ---------------- Load Hugging Face Pipelines ----------------
6
- # Summarizer (lightweight model that runs on CPU)
7
- summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
8
- # Text generation for eco tips
9
- generator = pipeline("text-generation", model="distilgpt2")
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"Suggest practical and actionable eco-friendly tips for sustainable living "
32
- f"related to: {problem_keywords}. Provide clear solutions and suggestions."
33
  )
34
- result = generator(prompt, max_length=200, num_return_sequences=1, do_sample=True)
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=150,
52
- min_length=40,
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
+