Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,54 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# ๋ชจ๋ธ ๋ก๋
|
| 5 |
model = pipeline("text-generation", model="skt/kogpt2-base-v2")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
st.title("
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
if
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from docx import Document
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
+
# ๋ชจ๋ธ ๋ก๋ (KoGPT2)
|
| 7 |
model = pipeline("text-generation", model="skt/kogpt2-base-v2")
|
| 8 |
|
| 9 |
+
# ํ์ผ ์
๋ก๋ UI
|
| 10 |
+
st.title("ํ์ผ ์
๋ก๋ ๋ฐ ์ฒ๋ฆฌ")
|
| 11 |
+
uploaded_word_file = st.file_uploader("Word ํ์ผ์ ์
๋ก๋ํ์ธ์ (.docx)", type="docx")
|
| 12 |
+
uploaded_excel_file = st.file_uploader("Excel ํ์ผ์ ์
๋ก๋ํ์ธ์ (.xlsx)", type="xlsx")
|
| 13 |
|
| 14 |
+
# Word ํ์ผ ์ฒ๋ฆฌ
|
| 15 |
+
if uploaded_word_file is not None:
|
| 16 |
+
doc = Document(uploaded_word_file)
|
| 17 |
+
word_content = []
|
| 18 |
+
|
| 19 |
+
# Word ๋ฌธ์์์ ํ
์คํธ ์ถ์ถ
|
| 20 |
+
for para in doc.paragraphs:
|
| 21 |
+
word_content.append(para.text)
|
| 22 |
+
|
| 23 |
+
word_text = "\n".join(word_content)
|
| 24 |
+
st.write("**์
๋ก๋๋ Word ํ์ผ์ ํ
์คํธ**:")
|
| 25 |
+
st.write(word_text)
|
| 26 |
+
|
| 27 |
+
# ํ
์คํธ ์ฒ๋ฆฌ (KoGPT2 ๋ชจ๋ธ ์ฌ์ฉ)
|
| 28 |
+
if st.button("Word ํ์ผ ํ
์คํธ ์ฒ๋ฆฌ"):
|
| 29 |
+
processed_text = model(word_text, max_length=100)[0]['generated_text']
|
| 30 |
+
st.write("**์ฒ๋ฆฌ๋ ํ
์คํธ**:")
|
| 31 |
+
st.write(processed_text)
|
| 32 |
|
| 33 |
+
# Excel ํ์ผ ์ฒ๋ฆฌ
|
| 34 |
+
if uploaded_excel_file is not None:
|
| 35 |
+
df = pd.read_excel(uploaded_excel_file)
|
| 36 |
+
st.write("**์
๋ก๋๋ Excel ํ์ผ**:")
|
| 37 |
+
st.write(df)
|
| 38 |
+
|
| 39 |
+
# ์์: 'Column_name' ์ด์ ๋ํด ํ
์คํธ ์ฒ๋ฆฌ
|
| 40 |
+
if 'Column_name' in df.columns:
|
| 41 |
+
df['Processed_Column'] = df['Column_name'].apply(lambda x: model(str(x), max_length=100)[0]['generated_text'])
|
| 42 |
+
st.write("**์ฒ๋ฆฌ๋ Excel ๋ฐ์ดํฐ**:")
|
| 43 |
+
st.write(df)
|
| 44 |
+
|
| 45 |
+
# ์ฒ๋ฆฌ๋ ๊ฒฐ๊ณผ๋ฅผ ์๋ก์ด Excel ํ์ผ๋ก ๋ค์ด๋ก๋
|
| 46 |
+
output_file = "processed_file.xlsx"
|
| 47 |
+
df.to_excel(output_file, index=False)
|
| 48 |
+
|
| 49 |
+
st.download_button(
|
| 50 |
+
label="์ฒ๋ฆฌ๋ Excel ํ์ผ ๋ค์ด๋ก๋",
|
| 51 |
+
data=open(output_file, "rb").read(),
|
| 52 |
+
file_name=output_file,
|
| 53 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
| 54 |
+
)
|