Spaces:
Sleeping
Sleeping
add upload
Browse files
app.py
CHANGED
@@ -1,8 +1,25 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
from nlp import analyze_sentiment, analyze_kakao_csv, get_json_result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
app = FastAPI()
|
5 |
|
6 |
@app.get("/")
|
7 |
def greet_json():
|
8 |
-
return {"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from nlp import analyze_sentiment, analyze_kakao_csv, get_json_result
|
2 |
+
from fastapi import FastAPI, UploadFile, File
|
3 |
+
from fastapi.responses import JSONResponse
|
4 |
+
import os
|
5 |
+
|
6 |
+
# 업로드 디렉토리 생성
|
7 |
+
UPLOAD_DIR = "uploads"
|
8 |
+
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
9 |
|
10 |
app = FastAPI()
|
11 |
|
12 |
@app.get("/")
|
13 |
def greet_json():
|
14 |
+
return {"v": 0.1}
|
15 |
+
|
16 |
+
@app.post("/upload/")
|
17 |
+
async def upload_file(file: UploadFile = File(...)):
|
18 |
+
file_location = os.path.join(UPLOAD_DIR, file.filename)
|
19 |
+
try:
|
20 |
+
contents = await file.read()
|
21 |
+
with open(file_location, "wb") as f:
|
22 |
+
f.write(contents)
|
23 |
+
return {"filename": file.filename, "saved_to": file_location}
|
24 |
+
except Exception as e:
|
25 |
+
return JSONResponse(status_code=500, content={"error": str(e)})
|