Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,32 +25,6 @@ print("-------")
|
|
| 25 |
print("started")
|
| 26 |
print("-------")
|
| 27 |
|
| 28 |
-
async def echo(websocket):
|
| 29 |
-
global userData
|
| 30 |
-
async for message in websocket:
|
| 31 |
-
data = json.loads(message)
|
| 32 |
-
if not "message" in message:
|
| 33 |
-
return
|
| 34 |
-
if not "token" in message:
|
| 35 |
-
return
|
| 36 |
-
m = data["message"]
|
| 37 |
-
token = data["token"]
|
| 38 |
-
docs = retriever.get_relevant_documents(m)
|
| 39 |
-
response = conversational_rag_chain.invoke(
|
| 40 |
-
{"input": m},
|
| 41 |
-
config={
|
| 42 |
-
"configurable": {"session_id": token}
|
| 43 |
-
},
|
| 44 |
-
)["answer"]
|
| 45 |
-
await websocket.send(json.dumps({"response": response}))
|
| 46 |
-
|
| 47 |
-
async def main():
|
| 48 |
-
async with serve(echo, "0.0.0.0", 7860):
|
| 49 |
-
await asyncio.Future()
|
| 50 |
-
|
| 51 |
-
def f():
|
| 52 |
-
asyncio.run(main())
|
| 53 |
-
Process(target=f).start()
|
| 54 |
if not os.path.isdir('database'):
|
| 55 |
os.system("unzip database.zip")
|
| 56 |
|
|
@@ -84,6 +58,33 @@ print("-------")
|
|
| 84 |
print("Embeddings")
|
| 85 |
print("-------")
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
vectorstore = Chroma.from_documents(documents=splits, embedding=embedding)
|
| 88 |
|
| 89 |
def format_docs(docs):
|
|
|
|
| 25 |
print("started")
|
| 26 |
print("-------")
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
if not os.path.isdir('database'):
|
| 29 |
os.system("unzip database.zip")
|
| 30 |
|
|
|
|
| 58 |
print("Embeddings")
|
| 59 |
print("-------")
|
| 60 |
|
| 61 |
+
async def echo(websocket):
|
| 62 |
+
global retriever, conversational_rag_chain
|
| 63 |
+
async for message in websocket:
|
| 64 |
+
data = json.loads(message)
|
| 65 |
+
if not "message" in message:
|
| 66 |
+
return
|
| 67 |
+
if not "token" in message:
|
| 68 |
+
return
|
| 69 |
+
m = data["message"]
|
| 70 |
+
token = data["token"]
|
| 71 |
+
docs = retriever.get_relevant_documents(m)
|
| 72 |
+
response = conversational_rag_chain.invoke(
|
| 73 |
+
{"input": m},
|
| 74 |
+
config={
|
| 75 |
+
"configurable": {"session_id": token}
|
| 76 |
+
},
|
| 77 |
+
)["answer"]
|
| 78 |
+
await websocket.send(json.dumps({"response": response}))
|
| 79 |
+
|
| 80 |
+
async def main():
|
| 81 |
+
async with serve(echo, "0.0.0.0", 7860):
|
| 82 |
+
await asyncio.Future()
|
| 83 |
+
|
| 84 |
+
def f():
|
| 85 |
+
asyncio.run(main())
|
| 86 |
+
Process(target=f).start()
|
| 87 |
+
|
| 88 |
vectorstore = Chroma.from_documents(documents=splits, embedding=embedding)
|
| 89 |
|
| 90 |
def format_docs(docs):
|