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"
        )