Spaces:
Sleeping
Sleeping
HUANG-Stephanie
commited on
Commit
•
14c5169
1
Parent(s):
04334e4
Update app.py
Browse files
app.py
CHANGED
@@ -80,50 +80,4 @@ async def search(query: str, k: int):
|
|
80 |
|
81 |
results = [{"page": idx, "image": "image_placeholder"} for idx in top_k_indices]
|
82 |
|
83 |
-
return {"results": results}
|
84 |
-
|
85 |
-
def index_gradio(file, ds):
|
86 |
-
"""Upload PDFs and get embeddings."""
|
87 |
-
url = "http://localhost:8082/index"
|
88 |
-
files = [("files", (f.name, f.file)) for f in file]
|
89 |
-
response = requests.post(url, files=files)
|
90 |
-
result = response.json()
|
91 |
-
return result['message'], ds, []
|
92 |
-
|
93 |
-
def search_gradio(query: str, ds, images, k):
|
94 |
-
"""Send a search query and get results."""
|
95 |
-
url = "http://localhost:8082/search"
|
96 |
-
payload = {'query': query, 'k': k}
|
97 |
-
response = requests.post(url, json=payload)
|
98 |
-
result = response.json()
|
99 |
-
results = result['results']
|
100 |
-
return results
|
101 |
-
|
102 |
-
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
103 |
-
gr.Markdown("# ColPali: Efficient Document Retrieval with Vision Language Models 📚")
|
104 |
-
|
105 |
-
with gr.Row():
|
106 |
-
with gr.Column(scale=2):
|
107 |
-
gr.Markdown("## 1️⃣ Upload PDFs")
|
108 |
-
file = gr.File(file_types=["pdf"], file_count="multiple", label="Upload PDFs")
|
109 |
-
|
110 |
-
convert_button = gr.Button("🔄 Index documents")
|
111 |
-
message = gr.Textbox("Files not yet uploaded", label="Status")
|
112 |
-
embeds = gr.State(value=[])
|
113 |
-
imgs = gr.State(value=[])
|
114 |
-
|
115 |
-
with gr.Column(scale=3):
|
116 |
-
gr.Markdown("## 2️⃣ Search")
|
117 |
-
query = gr.Textbox(placeholder="Enter your query here", label="Query")
|
118 |
-
k = gr.Slider(minimum=1, maximum=10, step=1, label="Number of results", value=1)
|
119 |
-
|
120 |
-
# Define the actions
|
121 |
-
search_button = gr.Button("🔍 Search", variant="primary")
|
122 |
-
output_gallery = gr.Gallery(label="Retrieved Documents", height=600, show_label=True)
|
123 |
-
|
124 |
-
convert_button.click(index_gradio, inputs=[file, embeds], outputs=[message, embeds, imgs])
|
125 |
-
search_button.click(search_gradio, inputs=[query, embeds, imgs, k], outputs=[output_gallery])
|
126 |
-
|
127 |
-
if __name__ == "__main__":
|
128 |
-
import uvicorn
|
129 |
-
uvicorn.run(app, host="0.0.0.0")
|
|
|
80 |
|
81 |
results = [{"page": idx, "image": "image_placeholder"} for idx in top_k_indices]
|
82 |
|
83 |
+
return {"results": results}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|