arad1367 commited on
Commit
e75727f
·
verified ·
1 Parent(s): ea12742

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -18
app.py CHANGED
@@ -34,7 +34,7 @@ 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
@@ -88,12 +88,26 @@ def process_pdf_and_query(pdf_file, user_query):
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,18 +121,6 @@ footer = """
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>
113
- <p>
114
- This application utilizes the ColPali model as a multimodal retriever,
115
- which retrieves relevant information from documents and generates answers
116
- using the Qwen/Qwen2-VL-2B-Instruct LLM (Large Language Model)
117
- via the Byaldi library, developed by Answer.ai.
118
- </p>
119
- </div>
120
- """
121
-
122
 
123
  demo = gr.Interface(
124
  fn=process_pdf_and_query,
@@ -130,10 +132,12 @@ demo = gr.Interface(
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>
@@ -145,6 +149,7 @@ css = """
145
  padding: 10px 20px;
146
  font-size: 16px;
147
  cursor: pointer;
 
148
  }
149
  .duplicate-button {
150
  background-color: green;
@@ -160,4 +165,5 @@ css = """
160
  """
161
  gr.HTML(css)
162
 
163
- demo.launch(debug=True)
 
 
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
 
88
 
89
  return output_text[0], num_images
90
 
91
+
92
  pdf_input = gr.File(label="Upload PDF")
93
  query_input = gr.Textbox(label="Enter your query", placeholder="Ask a question about the PDF")
94
+ output_text = gr.Textbox(label="Model Answer")
95
  output_images = gr.Textbox(label="Number of Images in PDF")
96
 
97
 
98
+ explanation = """
99
+ <div style="text-align: center; margin-bottom: 20px;">
100
+ <h2 style="font-weight: bold; font-size: 24px;">Multimodal RAG (Retrieval-Augmented Generation)</h2>
101
+ <p>
102
+ This application utilizes the ColPali model as a multimodal retriever,
103
+ which retrieves relevant information from documents and generates answers
104
+ using the Qwen/Qwen2-VL-2B-Instruct LLM (Large Language Model)
105
+ via the Byaldi library, developed by Answer.ai.
106
+ </p>
107
+ </div>
108
+ """
109
+
110
+
111
  footer = """
112
  <div style="text-align: center; margin-top: 20px;">
113
  <a href="https://www.linkedin.com/in/pejman-ebrahimi-4a60151a7/" target="_blank">LinkedIn</a> |
 
121
  </div>
122
  """
123
 
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
  demo = gr.Interface(
126
  fn=process_pdf_and_query,
 
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
+ submit_btn = gr.Button("Submit", elem_classes="submit-button")
140
+
141
 
142
  css = """
143
  <style>
 
149
  padding: 10px 20px;
150
  font-size: 16px;
151
  cursor: pointer;
152
+ margin: 10px; /* Add some space between buttons */
153
  }
154
  .duplicate-button {
155
  background-color: green;
 
165
  """
166
  gr.HTML(css)
167
 
168
+ # Launch the Gradio app
169
+ demo.launch(debug=True)