Spaces:
Sleeping
Sleeping
HUANG-Stephanie
commited on
Commit
•
df537e3
1
Parent(s):
958c116
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import os
|
|
3 |
import sys
|
4 |
|
5 |
from fastapi import FastAPI, File, UploadFile
|
|
|
6 |
import gradio as gr
|
7 |
import requests
|
8 |
from typing import List
|
@@ -41,7 +42,7 @@ ds = []
|
|
41 |
images = []
|
42 |
|
43 |
@app.post("/index")
|
44 |
-
|
45 |
global ds, images
|
46 |
images = []
|
47 |
ds = []
|
@@ -65,7 +66,7 @@ async def index(files: List[UploadFile] = File(...)):
|
|
65 |
return {"message": f"Uploaded and converted {len(images)} pages"}
|
66 |
|
67 |
@app.post("/search")
|
68 |
-
|
69 |
qs = []
|
70 |
with torch.no_grad():
|
71 |
batch_query = process_queries(processor, [query], mock_image)
|
@@ -80,4 +81,9 @@ 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}
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import sys
|
4 |
|
5 |
from fastapi import FastAPI, File, UploadFile
|
6 |
+
from fastapi.responses import RedirectResponse
|
7 |
import gradio as gr
|
8 |
import requests
|
9 |
from typing import List
|
|
|
42 |
images = []
|
43 |
|
44 |
@app.post("/index")
|
45 |
+
def index(files: List[UploadFile] = File(...)):
|
46 |
global ds, images
|
47 |
images = []
|
48 |
ds = []
|
|
|
66 |
return {"message": f"Uploaded and converted {len(images)} pages"}
|
67 |
|
68 |
@app.post("/search")
|
69 |
+
def search(query: str, k: int):
|
70 |
qs = []
|
71 |
with torch.no_grad():
|
72 |
batch_query = process_queries(processor, [query], mock_image)
|
|
|
81 |
|
82 |
results = [{"page": idx, "image": "image_placeholder"} for idx in top_k_indices]
|
83 |
|
84 |
+
return {"results": results}
|
85 |
+
|
86 |
+
# Rediriger la racine vers /docs
|
87 |
+
@app.get("/")
|
88 |
+
def read_root():
|
89 |
+
return RedirectResponse(url="/docs")
|