-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
142 lines (115 loc) · 4.66 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'''
from pdf_extractor import extract_text_from_pdf
from ocr import perform_ocr
from ner import perform_ner, visualize_entities
from qa import perform_qa
def main():
st.title("Document Processing Application")
# Sidebar for selecting document type
document_type = st.sidebar.radio("Select Document Type:", ("Manual Text", "PDF", "Image"))
text = "" # Initialize text variable
if document_type == "Manual Text":
st.sidebar.write("You selected Manual Text")
# Text input field for manual input
manual_text = st.text_area("Enter text here:", "")
text = manual_text.strip() # Set text variable to manual_text
elif document_type == "PDF":
st.sidebar.write("You selected PDF")
# Upload PDF file
uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
if uploaded_file is not None:
text = extract_text_from_pdf(uploaded_file)
st.write("Extracted text:")
st.write(text)
elif document_type == "Image":
st.sidebar.write("You selected Image")
# Get the input image from the user
input_image = get_image()
if input_image:
# Perform OCR on the image
text = perform_ocr(input_image)
st.header("OCR Text Extraction Results:")
st.write(text)
# Entity Recognition section
if st.sidebar.button("Entity Recognition"):
if text:
st.sidebar.subheader("Automated Entity Recognition:")
doc_med7, doc_bc5cdr, combined_entities = perform_ner(text)
html = visualize_entities(doc_med7, combined_entities)
st.write(html, unsafe_allow_html=True)
else:
st.warning("Please input some text before performing entity recognition.")
# Question Answering section
st.sidebar.markdown("---")
st.header("Question Answering")
question = st.text_input("Enter your query:")
if st.button("Search"):
if text:
if question:
answer = perform_qa(question, text)
st.subheader("Answer:")
st.write(answer)
else:
st.warning("Please enter a query before searching.")
else:
st.warning("Please input some text before querying.")
if __name__ == "__main__":
main()
'''
import streamlit as st
from pdf_extractor import extract_text_from_pdf
from ocr import get_image, perform_ocr
from ner import perform_ner, visualize_entities
from qa import perform_qa
def main():
st.title("Document Processing Application")
# Sidebar for selecting document type
document_type = st.sidebar.radio("Select Document Type:", ("Manual Text", "PDF", "Image"))
text = "" # Initialize text variable
if document_type == "Manual Text":
st.sidebar.write("You selected Manual Text")
# Text input field for manual input
manual_text = st.text_area("Enter text here:", "")
text = manual_text.strip() # Set text variable to manual_text
elif document_type == "PDF":
st.sidebar.write("You selected PDF")
# Upload PDF file
uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
if uploaded_file is not None:
text = extract_text_from_pdf(uploaded_file)
st.write("Extracted text:")
st.write(text)
elif document_type == "Image":
st.sidebar.write("You selected Image")
# Get the input image from the user
input_image = get_image()
if input_image:
# Perform OCR on the image
text = perform_ocr(input_image)
st.header("OCR Text Extraction Results:")
st.write(text)
# Entity Recognition section
if st.sidebar.button("Entity Recognition"):
if text:
st.sidebar.subheader("Automated Entity Recognition:")
doc_med7, doc_bc5cdr, combined_entities = perform_ner(text)
html = visualize_entities(doc_med7, combined_entities)
st.write(html, unsafe_allow_html=True)
else:
st.warning("Please input some text before performing entity recognition.")
# Question Answering section
st.sidebar.markdown("---")
st.header("Question Answering")
question = st.text_input("Enter your query:")
if st.button("Search"):
if text:
if question:
answer = perform_qa(question, text)
st.subheader("Answer:")
st.write(answer)
else:
st.warning("Please enter a query before searching.")
else:
st.warning("Please input some text before querying.")
if __name__ == "__main__":
main()