Fozan-Talat commited on
Commit
a91476c
·
1 Parent(s): 7c58552
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import uvicorn
 
2
  from fastapi import FastAPI, File, UploadFile
3
  from fastapi.responses import JSONResponse
4
  from datetime import datetime
@@ -17,15 +18,16 @@ os.environ["OPENAI_MODEL_NAME"] = 'gpt-3.5-turbo'
17
  os.environ["OPENAI_API_KEY"] = openai_api_key
18
 
19
  @app.post("/upload")
20
- async def upload_file(file: UploadFile = File(...)):
21
  current_datetime = datetime.now().strftime("%Y-%m-%d %H-%M-%S")
22
  filename = f'meeting-transcription/meeting-transcript_{current_datetime}.md'
 
23
 
24
  # Save file and convert to markdown
25
- content = await file.read()
26
- with open(f"{file.filename}", "wb") as docx_file:
27
  docx_file.write(content)
28
- with open(file.filename, "rb") as docx_file:
29
  result = mammoth.convert_to_markdown(docx_file)
30
  with open(filename, 'w', encoding='utf-8') as f:
31
  f.write(result.value)
 
1
  import uvicorn
2
+ import base64
3
  from fastapi import FastAPI, File, UploadFile
4
  from fastapi.responses import JSONResponse
5
  from datetime import datetime
 
18
  os.environ["OPENAI_API_KEY"] = openai_api_key
19
 
20
  @app.post("/upload")
21
+ async def upload_file(file: dict):
22
  current_datetime = datetime.now().strftime("%Y-%m-%d %H-%M-%S")
23
  filename = f'meeting-transcription/meeting-transcript_{current_datetime}.md'
24
+ print(filename)
25
 
26
  # Save file and convert to markdown
27
+ content = base64.b64decode(file.get("document"))
28
+ with open(f"{file.get("filename")}", "wb") as docx_file:
29
  docx_file.write(content)
30
+ with open(file.get("filename"), "rb") as docx_file:
31
  result = mammoth.convert_to_markdown(docx_file)
32
  with open(filename, 'w', encoding='utf-8') as f:
33
  f.write(result.value)