Spaces:
Sleeping
Sleeping
File size: 1,506 Bytes
7b36dc2 490b067 9c79a8d 490b067 44f1ab6 785706b 44f1ab6 490b067 59df57a 490b067 7b36dc2 59df57a 34bb5f6 59df57a 7b36dc2 10324f8 7b36dc2 59df57a 10324f8 59df57a 490b067 59df57a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
from nlp import analyze_kakao_csv, get_json_result
from fastapi import FastAPI, UploadFile, File
from fastapi.responses import JSONResponse
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import os
# ์
๋ก๋ ๋๋ ํ ๋ฆฌ ์์ฑ
UPLOAD_DIR = "uploads"
os.makedirs(UPLOAD_DIR, exist_ok=True)
app = FastAPI()
model_name = "nlp04/korean_sentiment_analysis_kcelectra"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
@app.get("/")
def greet_json():
return {"v": 0.1}
@app.post("/upload/")
async def upload_file(file: UploadFile = File(...)):
file_location = os.path.join(UPLOAD_DIR, file.filename)
try:
contents = await file.read()
with open(file_location, "wb") as f:
f.write(contents)
# analyze_kakao_upload_file์ด ๋น๋๊ธฐ ํจ์๋ผ๋ฉด await ํ์
results_df = await analyze_kakao_csv(contents, model, tokenizer)
if results_df is None:
return {"error": "CSV ํ์ผ์ ์ฝ์ ์ ์์ต๋๋ค."}
else:
result_json = get_json_result(results_df, "KCElectra")
print(f"\nAnalysis complete! Results saved to the 'results' folder.")
return {
"filename": file.filename,
"saved_to": file_location,
"result": result_json
}
except Exception as e:
return JSONResponse(status_code=500, content={"error": str(e)})
|