Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,13 +34,13 @@ processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", trust_rem
|
|
34 |
@spaces.GPU()
|
35 |
def process_pdf_and_query(pdf_file, user_query):
|
36 |
# Convert the PDF to images
|
37 |
-
images = convert_from_path(pdf_file.name)
|
38 |
num_images = len(images)
|
39 |
|
40 |
# Indexing the PDF in RAG
|
41 |
RAG.index(
|
42 |
input_path=pdf_file.name,
|
43 |
-
index_name="image_index",
|
44 |
store_collection_with_index=False,
|
45 |
overwrite=True
|
46 |
)
|
@@ -88,13 +88,12 @@ def process_pdf_and_query(pdf_file, user_query):
|
|
88 |
|
89 |
return output_text[0], num_images
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
|
97 |
-
# Footer HTML
|
98 |
footer = """
|
99 |
<div style="text-align: center; margin-top: 20px;">
|
100 |
<a href="https://www.linkedin.com/in/pejman-ebrahimi-4a60151a7/" target="_blank">LinkedIn</a> |
|
@@ -108,7 +107,6 @@ footer = """
|
|
108 |
</div>
|
109 |
"""
|
110 |
|
111 |
-
# Explanation about Multimodal RAG
|
112 |
explanation = """
|
113 |
<div style="text-align: center; margin-bottom: 20px;">
|
114 |
<h2 style="font-weight: bold; font-size: 24px;">Multimodal RAG (Retrieval-Augmented Generation)</h2>
|
@@ -121,23 +119,22 @@ explanation = """
|
|
121 |
</div>
|
122 |
"""
|
123 |
|
124 |
-
|
125 |
demo = gr.Interface(
|
126 |
fn=process_pdf_and_query,
|
127 |
-
inputs=[pdf_input, query_input],
|
128 |
-
outputs=[output_text, output_images],
|
129 |
-
title="Multimodal RAG with Image Query - By <a href='https://github.com/arad1367'>Pejman Ebrahimi</a>",
|
130 |
theme='freddyaboulton/dracula_revamped',
|
131 |
)
|
132 |
|
133 |
-
|
134 |
with demo:
|
135 |
-
gr.HTML(explanation)
|
136 |
-
gr.HTML(footer)
|
137 |
-
gr.DuplicateButton(value="Duplicate Space for private use", elem_classes="duplicate-button")
|
138 |
-
|
139 |
|
140 |
-
# Custom CSS for styling the button
|
141 |
css = """
|
142 |
<style>
|
143 |
.submit-button {
|
@@ -150,17 +147,17 @@ css = """
|
|
150 |
cursor: pointer;
|
151 |
}
|
152 |
.duplicate-button {
|
153 |
-
background-color:
|
154 |
color: white;
|
155 |
border: none;
|
156 |
border-radius: 5px;
|
157 |
padding: 10px 20px;
|
158 |
font-size: 16px;
|
159 |
cursor: pointer;
|
|
|
160 |
}
|
161 |
</style>
|
162 |
"""
|
163 |
gr.HTML(css)
|
164 |
|
165 |
-
|
166 |
-
demo.launch(debug=True) # Start the interface
|
|
|
34 |
@spaces.GPU()
|
35 |
def process_pdf_and_query(pdf_file, user_query):
|
36 |
# Convert the PDF to images
|
37 |
+
images = convert_from_path(pdf_file.name)
|
38 |
num_images = len(images)
|
39 |
|
40 |
# Indexing the PDF in RAG
|
41 |
RAG.index(
|
42 |
input_path=pdf_file.name,
|
43 |
+
index_name="image_index",
|
44 |
store_collection_with_index=False,
|
45 |
overwrite=True
|
46 |
)
|
|
|
88 |
|
89 |
return output_text[0], num_images
|
90 |
|
91 |
+
pdf_input = gr.File(label="Upload PDF")
|
92 |
+
query_input = gr.Textbox(label="Enter your query", placeholder="Ask a question about the PDF")
|
93 |
+
output_text = gr.Textbox(label="Model Answer")
|
94 |
+
output_images = gr.Textbox(label="Number of Images in PDF")
|
95 |
+
|
96 |
|
|
|
97 |
footer = """
|
98 |
<div style="text-align: center; margin-top: 20px;">
|
99 |
<a href="https://www.linkedin.com/in/pejman-ebrahimi-4a60151a7/" target="_blank">LinkedIn</a> |
|
|
|
107 |
</div>
|
108 |
"""
|
109 |
|
|
|
110 |
explanation = """
|
111 |
<div style="text-align: center; margin-bottom: 20px;">
|
112 |
<h2 style="font-weight: bold; font-size: 24px;">Multimodal RAG (Retrieval-Augmented Generation)</h2>
|
|
|
119 |
</div>
|
120 |
"""
|
121 |
|
122 |
+
|
123 |
demo = gr.Interface(
|
124 |
fn=process_pdf_and_query,
|
125 |
+
inputs=[pdf_input, query_input],
|
126 |
+
outputs=[output_text, output_images],
|
127 |
+
title="<div style='text-align: center; font-weight: bold; font-size: 28px;'>Multimodal RAG with Image Query - By <a href='https://github.com/arad1367' style='color: blue;'>Pejman Ebrahimi</a></div>",
|
128 |
theme='freddyaboulton/dracula_revamped',
|
129 |
)
|
130 |
|
131 |
+
|
132 |
with demo:
|
133 |
+
gr.HTML(explanation)
|
134 |
+
gr.HTML(footer)
|
135 |
+
gr.DuplicateButton(value="Duplicate Space for private use", elem_classes="duplicate-button")
|
136 |
+
gr.Button("Submit", elem_classes="submit-button")
|
137 |
|
|
|
138 |
css = """
|
139 |
<style>
|
140 |
.submit-button {
|
|
|
147 |
cursor: pointer;
|
148 |
}
|
149 |
.duplicate-button {
|
150 |
+
background-color: green;
|
151 |
color: white;
|
152 |
border: none;
|
153 |
border-radius: 5px;
|
154 |
padding: 10px 20px;
|
155 |
font-size: 16px;
|
156 |
cursor: pointer;
|
157 |
+
margin: 10px; /* Add some space between buttons */
|
158 |
}
|
159 |
</style>
|
160 |
"""
|
161 |
gr.HTML(css)
|
162 |
|
163 |
+
demo.launch(debug=True)
|
|