mitulagr2 commited on
Commit
aa67631
1 Parent(s): 06dc580

Update main.py

Browse files
Files changed (1) hide show
  1. app/main.py +6 -5
app/main.py CHANGED
@@ -4,7 +4,8 @@ import pathlib
4
  import time
5
  import re
6
  from typing import List
7
- from fastapi import FastAPI, Request, Depends
 
8
  from fastapi.middleware import Middleware
9
  from fastapi.middleware.cors import CORSMiddleware
10
  from fastapi.responses import StreamingResponse
@@ -53,12 +54,12 @@ async def process_input(text: str):
53
  generator = re.split(r'(\s)', message)
54
  return StreamingResponse(astreamer(generator), media_type='text/event-stream')
55
 
56
- async def parse_body(request: Request):
57
- data = await request.body()
58
- return data
59
 
60
  @app.post("/upload")
61
- def upload(data = Depends(parse_body)):
62
  if data.get('bytes', None) and data.get('filename', None):
63
  try:
64
  filename = data['filename']
 
4
  import time
5
  import re
6
  from typing import List
7
+ from pydantic import BaseModel
8
+ from fastapi import FastAPI
9
  from fastapi.middleware import Middleware
10
  from fastapi.middleware.cors import CORSMiddleware
11
  from fastapi.responses import StreamingResponse
 
54
  generator = re.split(r'(\s)', message)
55
  return StreamingResponse(astreamer(generator), media_type='text/event-stream')
56
 
57
+ class File(BaseModel):
58
+ bytes: bytes
59
+ filename: str
60
 
61
  @app.post("/upload")
62
+ def upload(data: File):
63
  if data.get('bytes', None) and data.get('filename', None):
64
  try:
65
  filename = data['filename']