Spaces:
Runtime error
Runtime error
Update main.py
Browse files- app/main.py +6 -2
app/main.py
CHANGED
|
@@ -7,6 +7,7 @@ from pathlib import Path
|
|
| 7 |
from fastapi import FastAPI, UploadFile
|
| 8 |
from fastapi.middleware import Middleware
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 10 |
from .rag import ChatPDF
|
| 11 |
|
| 12 |
middleware = [
|
|
@@ -24,8 +25,10 @@ files_dir = os.path.expanduser("~/wtp_be_files/")
|
|
| 24 |
session_assistant = ChatPDF()
|
| 25 |
# session_messages = []
|
| 26 |
|
|
|
|
|
|
|
| 27 |
@app.get("/query")
|
| 28 |
-
def process_input(text: str):
|
| 29 |
if text and len(text.strip()) > 0:
|
| 30 |
text = text.strip()
|
| 31 |
print("PRINTING STREAM")
|
|
@@ -33,9 +36,10 @@ def process_input(text: str):
|
|
| 33 |
print(agent_text_stream)
|
| 34 |
for text in agent_text_stream:
|
| 35 |
print(text)
|
|
|
|
| 36 |
# session_messages.append((text, True))
|
| 37 |
# session_messages.append((agent_text, False))
|
| 38 |
-
return
|
| 39 |
|
| 40 |
|
| 41 |
@app.post("/upload")
|
|
|
|
| 7 |
from fastapi import FastAPI, UploadFile
|
| 8 |
from fastapi.middleware import Middleware
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
| 10 |
+
from fastapi.responses import StreamingResponse
|
| 11 |
from .rag import ChatPDF
|
| 12 |
|
| 13 |
middleware = [
|
|
|
|
| 25 |
session_assistant = ChatPDF()
|
| 26 |
# session_messages = []
|
| 27 |
|
| 28 |
+
# async def stream_generator()
|
| 29 |
+
|
| 30 |
@app.get("/query")
|
| 31 |
+
async def process_input(text: str):
|
| 32 |
if text and len(text.strip()) > 0:
|
| 33 |
text = text.strip()
|
| 34 |
print("PRINTING STREAM")
|
|
|
|
| 36 |
print(agent_text_stream)
|
| 37 |
for text in agent_text_stream:
|
| 38 |
print(text)
|
| 39 |
+
# yield text
|
| 40 |
# session_messages.append((text, True))
|
| 41 |
# session_messages.append((agent_text, False))
|
| 42 |
+
return StreamingResponse(agent_text_stream, media_type='text/event-stream')
|
| 43 |
|
| 44 |
|
| 45 |
@app.post("/upload")
|