File size: 1,970 Bytes
7dc5dac 202a7ab 7dc5dac 202a7ab 3063eef 7dc5dac 202a7ab f297628 202a7ab f297628 202a7ab |
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 46 47 48 49 50 51 52 53 54 55 |
import streamlit as st
import pandas as pd
from docx import Document
from transformers import pipeline
# λͺ¨λΈ λ‘λ (KoGPT2)
model = pipeline("text-generation", model="skt/kogpt2-base-v2")
# νμΌ μ
λ‘λ UI
st.title("νμΌ μ
λ‘λ λ° μ²λ¦¬")
uploaded_word_file = st.file_uploader("Word νμΌμ μ
λ‘λνμΈμ (.docx)", type="docx")
uploaded_excel_file = st.file_uploader("Excel νμΌμ μ
λ‘λνμΈμ (.xlsx)", type="xlsx")
# Word νμΌ μ²λ¦¬
if uploaded_word_file is not None:
doc = Document(uploaded_word_file)
word_content = []
# Word λ¬Έμμμ ν
μ€νΈ μΆμΆ
for para in doc.paragraphs:
word_content.append(para.text)
word_text = "\n".join(word_content)
st.write("**μ
λ‘λλ Word νμΌμ ν
μ€νΈ**:")
st.write(word_text)
# ν
μ€νΈ μ²λ¦¬ (KoGPT2 λͺ¨λΈ μ¬μ©)
if st.button("Word νμΌ ν
μ€νΈ μ²λ¦¬"):
processed_text = model(word_text, max_length=100)[0]['generated_text']
st.write("**μ²λ¦¬λ ν
μ€νΈ**:")
st.write(processed_text)
# Excel νμΌ μ²λ¦¬
if uploaded_excel_file is not None:
df = pd.read_excel(uploaded_excel_file)
st.write("**μ
λ‘λλ Excel νμΌ**:")
st.write(df)
# μμ: 'Column_name' μ΄μ λν΄ ν
μ€νΈ μ²λ¦¬
if 'Column_name' in df.columns:
df['Processed_Column'] = df['Column_name'].apply(lambda x: model(str(x), max_length=100)[0]['generated_text'])
st.write("**μ²λ¦¬λ Excel λ°μ΄ν°**:")
st.write(df)
# μ²λ¦¬λ κ²°κ³Όλ₯Ό μλ‘μ΄ Excel νμΌλ‘ λ€μ΄λ‘λ
output_file = "processed_file.xlsx"
df.to_excel(output_file, index=False)
st.download_button(
label="μ²λ¦¬λ Excel νμΌ λ€μ΄λ‘λ",
data=open(output_file, "rb").read(),
file_name=output_file,
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)
|