Spaces:
Running
Running
chabane
commited on
Commit
·
6310b8b
1
Parent(s):
fc61dfc
change in main
Browse files
main.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import FastAPI,Request,File,UploadFile
|
| 2 |
from fastapi.templating import Jinja2Templates
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
from fastapi.responses import HTMLResponse,JSONResponse
|
|
@@ -110,15 +110,18 @@ def interpret(file_img:UploadFile=File(...)):
|
|
| 110 |
@app.post("/summerize")
|
| 111 |
def summerzation(file:UploadFile=File(...)):
|
| 112 |
try:
|
| 113 |
-
|
| 114 |
extension = file.filename.split(".")[-1]
|
| 115 |
-
supported_ext=["pdf","xlsx","docx","ppt"]
|
| 116 |
if extension not in supported_ext :
|
| 117 |
return JSONResponse(content={"error": "Unsupported file type"},status_code=400)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
file_bytes = file.file.read()
|
| 119 |
|
| 120 |
-
|
| 121 |
-
return JSONResponse(content={"error": "too large file "},status_code=400)
|
| 122 |
if extension == "pdf":
|
| 123 |
text = get_text_from_PDF(file_bytes)
|
| 124 |
elif extension == "docx":
|
|
@@ -146,7 +149,7 @@ def summerzation(file:UploadFile=File(...)):
|
|
| 146 |
|
| 147 |
|
| 148 |
@app.post("/plot")
|
| 149 |
-
async def plot(user_need:str,file:UploadFile=File(...)):
|
| 150 |
try:
|
| 151 |
extension = file.filename.split(".")[-1]
|
| 152 |
Supported_extensions = ["xlsx","xls"]
|
|
@@ -158,9 +161,10 @@ async def plot(user_need:str,file:UploadFile=File(...)):
|
|
| 158 |
if len(file_bytes) > MAX_SIZE :
|
| 159 |
return JSONResponse(content={"error": "too large file "},status_code=400)
|
| 160 |
|
|
|
|
| 161 |
|
| 162 |
df = pd.read_excel(io=io.BytesIO(file_bytes))
|
| 163 |
-
|
| 164 |
message = f"""
|
| 165 |
You are a helpful assistant that helps users write Python code.
|
| 166 |
## Requirements:
|
|
|
|
| 1 |
+
from fastapi import FastAPI,Request,File,UploadFile,Form
|
| 2 |
from fastapi.templating import Jinja2Templates
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
from fastapi.responses import HTMLResponse,JSONResponse
|
|
|
|
| 110 |
@app.post("/summerize")
|
| 111 |
def summerzation(file:UploadFile=File(...)):
|
| 112 |
try:
|
| 113 |
+
|
| 114 |
extension = file.filename.split(".")[-1]
|
| 115 |
+
supported_ext=["pdf","xlsx","docx","ppt","xls"]
|
| 116 |
if extension not in supported_ext :
|
| 117 |
return JSONResponse(content={"error": "Unsupported file type"},status_code=400)
|
| 118 |
+
if file.size > MAX_SIZE:
|
| 119 |
+
return JSONResponse(content={"error": "file is too large "},status_code=400)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
file_bytes = file.file.read()
|
| 123 |
|
| 124 |
+
|
|
|
|
| 125 |
if extension == "pdf":
|
| 126 |
text = get_text_from_PDF(file_bytes)
|
| 127 |
elif extension == "docx":
|
|
|
|
| 149 |
|
| 150 |
|
| 151 |
@app.post("/plot")
|
| 152 |
+
async def plot(user_need:str=Form(...),file:UploadFile=File(...)):
|
| 153 |
try:
|
| 154 |
extension = file.filename.split(".")[-1]
|
| 155 |
Supported_extensions = ["xlsx","xls"]
|
|
|
|
| 161 |
if len(file_bytes) > MAX_SIZE :
|
| 162 |
return JSONResponse(content={"error": "too large file "},status_code=400)
|
| 163 |
|
| 164 |
+
|
| 165 |
|
| 166 |
df = pd.read_excel(io=io.BytesIO(file_bytes))
|
| 167 |
+
|
| 168 |
message = f"""
|
| 169 |
You are a helpful assistant that helps users write Python code.
|
| 170 |
## Requirements:
|