Amritpal Singh commited on
Commit
b751517
·
1 Parent(s): a001878

re-old one need UI change

Browse files
Files changed (2) hide show
  1. README.md +3 -3
  2. app.py +26 -31
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
- title: LexPilot
3
- emoji: "🧭"
4
  colorFrom: blue
5
  colorTo: blue
6
  sdk: streamlit
@@ -9,4 +9,4 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- LexPilot™ ingests text, PDF, and Word files to instantly analyze contracts, providing concise summaries and targeted Q&A for fast, precise legal and procurement insights.
 
1
  ---
2
+ title: DocAnalyzer Pro
3
+ emoji: "📄"
4
  colorFrom: blue
5
  colorTo: blue
6
  sdk: streamlit
 
9
  pinned: false
10
  ---
11
 
12
+ DocAnalyzer Pro is a Streamlit app for document question answering and summarization using Hugging Face Transformers.
app.py CHANGED
@@ -3,6 +3,10 @@ os.environ["STREAMLIT_SERVER_PORT"] = "8501"
3
  os.environ["STREAMLIT_SERVER_HEADLESS"] = "true"
4
 
5
  import streamlit as st
 
 
 
 
6
  from transformers import pipeline
7
  from PyPDF2 import PdfReader
8
  import docx
@@ -11,34 +15,13 @@ import psutil
11
  from pathlib import Path
12
  import torch
13
 
14
- # Page config with wide layout
15
- st.set_page_config(page_title="LexPilot", layout="wide")
16
-
17
- # Sidebar with project info
18
- with st.sidebar:
19
- st.title("LexPilot™")
20
- st.markdown(
21
- """
22
- LexPilot™ ingests text, PDF, and Word files to instantly analyze contracts.
23
- It delivers concise summaries and lets you ask targeted questions—
24
- giving fast, precise insights to speed up legal and procurement reviews.
25
- """
26
- )
27
- st.markdown("---")
28
- st.write("### System Status")
29
- try:
30
- device_status = 'GPU ✅' if torch.cuda.is_available() else 'CPU ⚠️'
31
- except:
32
- device_status = 'CPU (torch not configured)'
33
- st.text(f"Device: {device_status}")
34
- st.text(f"Memory: {psutil.virtual_memory().percent}% used")
35
- st.text(f"CPU: {psutil.cpu_percent()}% used")
36
 
37
- # Setup cache directory for models
38
  def setup_environment():
39
  cache_dir = Path(".cache/models")
40
  try:
41
  cache_dir.mkdir(exist_ok=True, parents=True)
 
42
  except Exception as e:
43
  st.error(f"Failed to create cache directory: {e}")
44
  return cache_dir
@@ -48,19 +31,23 @@ cache_dir = setup_environment()
48
  @st.cache_resource(ttl=3600)
49
  def load_models():
50
  try:
 
51
  qa_model = pipeline(
52
  "question-answering",
53
  model="distilbert-base-cased-distilled-squad",
54
  device=-1
55
  )
 
 
56
  summarizer_model = pipeline(
57
  "summarization",
58
- model="sshleifer/distilbart-cnn-6-6",
59
  device=-1
60
  )
 
61
  return {'qa': qa_model, 'summarizer': summarizer_model}
62
  except Exception as e:
63
- st.error(f"Failed to load models: {e}")
64
  st.stop()
65
 
66
  models = load_models()
@@ -101,8 +88,8 @@ def generate_summary(text, max_length=150):
101
  st.error(f"Summarization failed: {e}")
102
  return ""
103
 
104
- # Main UI title
105
- st.title("📄 LexPilot")
106
 
107
  with st.expander("📤 Upload Document", expanded=True):
108
  uploaded_file = st.file_uploader("Choose PDF/DOCX", type=["pdf", "docx"])
@@ -141,7 +128,15 @@ with tab2:
141
  st.success(f"Generated in {time.time()-start_time:.1f}s")
142
  st.markdown(f"**Summary:**\n\n{summary}")
143
 
144
- # Show cache dir path in sidebar (optional)
145
- with st.sidebar:
146
- st.markdown("---")
147
- st.write(f"Cache directory: {cache_dir}")
 
 
 
 
 
 
 
 
 
3
  os.environ["STREAMLIT_SERVER_HEADLESS"] = "true"
4
 
5
  import streamlit as st
6
+ st.set_page_config(page_title="DocAnalyzer Pro", layout="wide")
7
+
8
+ st.write("Step 1: Imports done")
9
+
10
  from transformers import pipeline
11
  from PyPDF2 import PdfReader
12
  import docx
 
15
  from pathlib import Path
16
  import torch
17
 
18
+ st.write("Step 2: Libraries imported")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
 
20
  def setup_environment():
21
  cache_dir = Path(".cache/models")
22
  try:
23
  cache_dir.mkdir(exist_ok=True, parents=True)
24
+ st.write(f"Step 3: Cache directory setup at {cache_dir}")
25
  except Exception as e:
26
  st.error(f"Failed to create cache directory: {e}")
27
  return cache_dir
 
31
  @st.cache_resource(ttl=3600)
32
  def load_models():
33
  try:
34
+ st.info("Loading QA model...")
35
  qa_model = pipeline(
36
  "question-answering",
37
  model="distilbert-base-cased-distilled-squad",
38
  device=-1
39
  )
40
+ st.info("QA model loaded.")
41
+ st.info("Loading summarizer model...")
42
  summarizer_model = pipeline(
43
  "summarization",
44
+ model="sshleifer/distilbart-cnn-6-6", # smaller model for faster startup
45
  device=-1
46
  )
47
+ st.info("Summarizer model loaded.")
48
  return {'qa': qa_model, 'summarizer': summarizer_model}
49
  except Exception as e:
50
+ st.error(f"Failed to load models: {e}")
51
  st.stop()
52
 
53
  models = load_models()
 
88
  st.error(f"Summarization failed: {e}")
89
  return ""
90
 
91
+ st.title("📄 DocAnalyzer Pro")
92
+ st.write("Step 4: UI started")
93
 
94
  with st.expander("📤 Upload Document", expanded=True):
95
  uploaded_file = st.file_uploader("Choose PDF/DOCX", type=["pdf", "docx"])
 
128
  st.success(f"Generated in {time.time()-start_time:.1f}s")
129
  st.markdown(f"**Summary:**\n\n{summary}")
130
 
131
+ with st.expander("⚙️ System Status"):
132
+ try:
133
+ device_status = 'GPU ✅' if torch.cuda.is_available() else 'CPU ⚠️'
134
+ except:
135
+ device_status = 'CPU (torch not configured)'
136
+ st.code(f"""
137
+ Models loaded: {', '.join(models.keys())}
138
+ Device: {device_status}
139
+ Memory: {psutil.virtual_memory().percent}% used
140
+ CPU: {psutil.cpu_percent()}% used
141
+ Cache location: {cache_dir}
142
+ """)