Nawal20 commited on
Commit
2bd4c2f
·
verified ·
1 Parent(s): b614604

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -29
app.py CHANGED
@@ -1,34 +1,28 @@
1
  import streamlit as st
2
  import subprocess
3
- import pdfplumber
4
- import camelot
5
- import tabula
6
- from transformers import pipeline
7
  import re
8
  import plotly.express as px
9
  import pandas as pd
10
 
11
- # Ensure required libraries are installed
12
- try:
13
- import torch
14
- except ImportError:
15
- subprocess.check_call(["pip", "install", "torch", "pandas"])
16
- try:
17
- import camelot
18
- except ImportError:
19
- subprocess.check_call(["pip", "install", "camelot-py[cv]"])
20
- try:
21
- import tabula
22
- except ImportError:
23
- subprocess.check_call(["pip", "install", "tabula-py"])
24
- try:
25
- import pdfplumber
26
- except ImportError:
27
- subprocess.check_call(["pip", "install", "pdfplumber"])
28
- try:
29
- import plotly
30
- except ImportError:
31
- subprocess.check_call(["pip", "install", "plotly"])
32
 
33
  # NLP Model for summarization
34
  summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
@@ -77,8 +71,6 @@ if input_type == "Upload PDF":
77
  for i, table in enumerate(tables):
78
  st.write(f"Table {i+1}")
79
  st.dataframe(table.df)
80
- # Save table to CSV (optional)
81
- # table.to_csv(f"table_{i+1}.csv")
82
  else:
83
  st.warning("No tables found using Camelot.")
84
  except Exception as e:
@@ -92,8 +84,6 @@ if input_type == "Upload PDF":
92
  for i, table in enumerate(tabula_tables):
93
  st.write(f"Table {i+1}")
94
  st.dataframe(table)
95
- # Save table to CSV (optional)
96
- # table.to_csv(f"tabula_table_{i+1}.csv")
97
  else:
98
  st.warning("No tables found using Tabula.")
99
  except Exception as e:
 
1
  import streamlit as st
2
  import subprocess
 
 
 
 
3
  import re
4
  import plotly.express as px
5
  import pandas as pd
6
 
7
+ # Ensure required libraries are installed and imported
8
+ def ensure_library_installed(library_name, install_name=None):
9
+ """Ensure a library is installed and import it."""
10
+ try:
11
+ globals()[library_name] = __import__(library_name)
12
+ except ImportError:
13
+ install_name = install_name or library_name
14
+ subprocess.check_call(["pip", "install", install_name])
15
+ globals()[library_name] = __import__(library_name)
16
+
17
+ # Ensure required libraries
18
+ ensure_library_installed("torch")
19
+ ensure_library_installed("camelot", "camelot-py[cv]")
20
+ ensure_library_installed("tabula", "tabula-py")
21
+ ensure_library_installed("pdfplumber")
22
+ ensure_library_installed("plotly")
23
+
24
+ # Import other required modules
25
+ from transformers import pipeline
 
 
26
 
27
  # NLP Model for summarization
28
  summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
 
71
  for i, table in enumerate(tables):
72
  st.write(f"Table {i+1}")
73
  st.dataframe(table.df)
 
 
74
  else:
75
  st.warning("No tables found using Camelot.")
76
  except Exception as e:
 
84
  for i, table in enumerate(tabula_tables):
85
  st.write(f"Table {i+1}")
86
  st.dataframe(table)
 
 
87
  else:
88
  st.warning("No tables found using Tabula.")
89
  except Exception as e: