Spaces:
Sleeping
Sleeping
Commit
·
e960d63
1
Parent(s):
89dc8b2
deepnote update
Browse files- app.py +25 -3
- requirements.txt +2 -1
app.py
CHANGED
@@ -2,6 +2,7 @@ from fastapi import FastAPI
|
|
2 |
from pydantic import BaseModel
|
3 |
import faq as faq
|
4 |
import uvicorn
|
|
|
5 |
|
6 |
app = FastAPI()
|
7 |
|
@@ -14,11 +15,32 @@ class Request(BaseModel):
|
|
14 |
|
15 |
|
16 |
@app.post("/api/v1/ask")
|
17 |
-
async def
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
return result
|
21 |
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
if __name__ == "__main__":
|
24 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
2 |
from pydantic import BaseModel
|
3 |
import faq as faq
|
4 |
import uvicorn
|
5 |
+
import gradio as gr
|
6 |
|
7 |
app = FastAPI()
|
8 |
|
|
|
15 |
|
16 |
|
17 |
@app.post("/api/v1/ask")
|
18 |
+
async def ask_api(request: Request):
|
19 |
+
return ask(
|
20 |
+
request.sheet_url, request.page_content_column, request.k, request.question
|
21 |
+
)
|
22 |
+
|
23 |
+
|
24 |
+
def ask(sheet_url: str, page_content_column: str, k: int, question: str):
|
25 |
+
vectordb = faq.load_vectordb(sheet_url, page_content_column)
|
26 |
+
result = faq.similarity_search(vectordb, question, k=k)
|
27 |
return result
|
28 |
|
29 |
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=ask,
|
32 |
+
inputs=[
|
33 |
+
gr.Textbox(label="Google Sheet URL"),
|
34 |
+
gr.Textbox(label="Question Column"),
|
35 |
+
gr.Slider(1, 5, step=1, label="K"),
|
36 |
+
gr.Textbox(label="Question"),
|
37 |
+
],
|
38 |
+
outputs=[gr.JSON(label="Answer")],
|
39 |
+
allow_flagging="never",
|
40 |
+
)
|
41 |
+
|
42 |
+
app = gr.mount_gradio_app(app, iface, path="/")
|
43 |
+
|
44 |
+
|
45 |
if __name__ == "__main__":
|
46 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
requirements.txt
CHANGED
@@ -3,4 +3,5 @@ langchain
|
|
3 |
sentence_transformers
|
4 |
awadb
|
5 |
fastapi
|
6 |
-
uvicorn
|
|
|
|
3 |
sentence_transformers
|
4 |
awadb
|
5 |
fastapi
|
6 |
+
uvicorn
|
7 |
+
gradio
|