Update app.py
Browse files24 unmodified lines2526272829303132333435363738394041424344454624 unmodified lines# ๊ณผ์ # ์๋ ํ ์คํธ ์ถ์ถ ํจ์๋ฅผ ์์ฑdef get_text_file(docs):# Assuming the document is a text filetext = docs.getvalue().decode('utf-8')return [text]def get_csv_file(docs):# Assuming the document is a CSV filecsv_loader = CSVLoader(docs)csv_doc = csv_loader.load()return csv_docdef get_json_file(docs):# Assuming the document is a JSON filejson_loader = JSONLoader(docs)json_doc = json_loader.load()return json_doc24 unmodified lines252627282930313233343536373839404142434445464748495051525354555657585924 unmodified lines# ๊ณผ์ # ์๋ ํ ์คํธ ์ถ์ถ ํจ์๋ฅผ ์์ฑ# ์๋ ์ฝ๋๋ get_text_file, get_csv_file, get_json_file ํจ์ ๋ด์ฉ๋ง ๋ณ๊ฒฝ๋์์ต๋๋ค.def get_text_file(text_docs):temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.temp_filepath = os.path.join(temp_dir.name, text_doce.name) # ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์์ฑํฉ๋๋ค.with open(temp_filepath, "wb") as f:f.write(text_docs.getvalue()) # text ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.text_loader = TextLoader(temp_filepath) # TextLoader๋ฅผ ์ฌ์ฉํด text๋ฅผ ๋ก๋ํฉ๋๋ค.text_doc = text_loader.load() # ํ ์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.return text_doc # ์ถ์ถํ ํ ์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.def get_csv_file(csv_docs):temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.temp_filepath = os.path.join(temp_dir.name, csv_doce.name) # ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์์ฑํฉ๋๋ค.with open(temp_filepath, "wb") as f:f.write(csv_docs.getvalue()) # CSV ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.csv_loader = CSVLoader(temp_filepath) # CSVLoader๋ฅผ ์ฌ์ฉํด CSV๋ฅผ ๋ก๋ํฉ๋๋ค.csv_doc = csv_loader.load() # ํ ์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.return csv_doc # ์ถ์ถํ ํ ์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.def get_json_file(json_docs):temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.temp_filepath = os.path.join(temp_dir.name, json_doce.name) # ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์์ฑํฉ๋๋ค.with open(temp_filepath, "wb") as f:f.write(json_docs.getvalue()) # JSON ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.json_loader = JSONLoader(temp_filepath, jq_schema='.messages[].content', text_content=False) # JSONLoader๋ฅผ ์ฌ์ฉํด JSON๋ฅผ ๋ก๋ํฉ๋๋ค.json_doc = json_loader.load() # ํ ์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.return json_doc # ์ถ์ถํ ํ ์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
app.py+29-16