File size: 3,980 Bytes
e69350d
 
 
4e2a346
e69350d
4e2a346
87d23c1
e69350d
924cf8c
5887467
924cf8c
91674d2
87d23c1
cb8c619
87d23c1
6d85b7e
91674d2
6d85b7e
fd2d82a
91674d2
cb8c619
91674d2
87d23c1
91674d2
 
c2c17ab
91674d2
 
f049b45
91674d2
022cf58
91674d2
c2c17ab
91674d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
022cf58
e69350d
91674d2
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from annotated_text import annotated_text
import streamlit as st
import openai
import os

# OpenAI API ์„ค์ • (ํ™˜๊ฒฝ ๋ณ€์ˆ˜์—์„œ ์ฝ์–ด์˜ด)
openai.api_key = os.getenv("OPENAI_API_KEY")  # ์‹ค์ œ ์ฝ”๋“œ์—์„œ ์ฃผ์„ ํ•ด์ œ

def main():
    st.title("ํ•œ๊ตญ์–ด ํ•™์Šต์ž๋ฅผ ์œ„ํ•œ HCI tools")
    
    col1, col2 = st.columns(2)

    with col1:
        st.header("์ง€๋ฌธ")
       
        user_text = """๋ฏผ์ฃผ์ฃผ์˜ ์‚ฌํšŒ๋Š” ๊ตญ๋ฏผ์ด ์ •์น˜์— ์ฐธ์—ฌํ•  ๊ถŒ๋ฆฌ๋ฅผ ๋ณด์žฅํ•œ๋‹ค. ๊ทธ๋Ÿฌํ•œ ๊ถŒ๋ฆฌ๋ฅผ ์ฐธ์ •๊ถŒ์ด๋ผ ํ•˜๋Š”๋ฐ, ์ด๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ โ€˜์„ ๊ฑฐโ€™๋กœ ์‹คํ˜„๋œ๋‹ค. ์„ ๊ฑฐ๋Š” ์‚ฌํšŒ ์ง‘๋‹จ์˜ ๋Œ€ํ‘œ์ž๋‚˜ ๊ณต์ง์ž๋ฅผ ์„ ์ถœํ•˜์—ฌ ๊ทธ๋“ค์—๊ฒŒ ๋Œ€ํ‘œ์„ฑ์„ ๋ถ€์—ฌํ•˜๋Š” ํ–‰์œ„์ด๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ ๋†’์€ ํˆฌํ‘œ์œจ์€ ๋ฏผ์ฃผ์ฃผ์˜์˜ ์ •๋‹น์„ฑ ํ™•๋ณด์™€ ๊นŠ์€ ๊ด€๋ จ์ด ์žˆ๋‹ค."""
        st.write(user_text)

    # ์ƒ๋‹จ ์ปจํ…Œ์ด๋„ˆ
    with col2:
        st.header("์กฐ์ž‘ ํŒจ๋„")
        user_input = st.text_input("๋ชจ๋ฅด๋Š” ๋ฌธ์žฅ์ด๋‚˜ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”:", "")
        
        # ๋ฒ„ํŠผ row
        cols = st.columns(4)
        with cols[0]:
            btn_keyword = st.button("ํ‚ค์›Œ๋“œ ์ฐพ๊ธฐ")
        with cols[1]:
            btn_explanation = st.button("์ถ”๊ฐ€ ์„ค๋ช…")
        with cols[2]:
            btn_simple = st.button("์‰ฌ์šด ํ‘œํ˜„")
        with cols[3]:
            btn_rewrite = st.button("๋‹ค์‹œ ์“ฐ๊ธฐ")

    # ํ•˜๋‹จ ์ปจํ…Œ์ด๋„ˆ
    with st.container():
        st.header("๊ฒฐ๊ณผ")

        if btn_keyword:
            # ํ‚ค์›Œ๋“œ ์ฐพ๊ธฐ ๋กœ์ง
            # OpenAI API ํ˜ธ์ถœ์€ ์‹ค์ œ๋กœ ์‹คํ–‰ํ•˜์‹ค ๋•Œ ์ฃผ์„์„ ํ•ด์ œํ•ด์ฃผ์„ธ์š”.

            response = openai.ChatCompletion.create(
                model="gpt-3.5-turbo-16k",
                prompt=f"Extract key words from the text: {user_text}",
                temperature=0.1,
                max_tokens=200
            )
            keywords = response['choices'][0]['text']

            keywords = "๋ฏผ์ฃผ์ฃผ์˜, ๊ตญ๋ฏผ, ์ •์น˜, ์ฐธ์—ฌ, ๊ถŒ๋ฆฌ, ์ฐธ์ •๊ถŒ, ์„ ๊ฑฐ, ์‚ฌํšŒ ์ง‘๋‹จ, ๋Œ€ํ‘œ์ž, ๊ณต์ง์ž, ๋Œ€ํ‘œ์„ฑ, ํˆฌํ‘œ์œจ, ์ •๋‹น์„ฑ"  # ์˜ˆ์‹œ
            st.write(f"ํ‚ค์›Œ๋“œ: {keywords}")

        if btn_explanation:
            # ์ถ”๊ฐ€ ์„ค๋ช… ๋กœ์ง
            # OpenAI API ํ˜ธ์ถœ์€ ์‹ค์ œ๋กœ ์‹คํ–‰ํ•˜์‹ค ๋•Œ ์ฃผ์„์„ ํ•ด์ œํ•ด์ฃผ์„ธ์š”.

            response = openai.ChatCompletion.create(
                model="gpt-3.5-turbo-16k",
                prompt=f"Explain the term '{user_input}' in the context of the text: {user_text}",
                temperature=0.1,
                max_tokens=200
            )
            explanation = response['choices'][0]['text']

            explanation = "์—ฌ๊ธฐ์— ์ถ”๊ฐ€ ์„ค๋ช…์ด ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค."  # ์˜ˆ์‹œ
            st.write(f"์„ค๋ช…: {explanation}")

        if btn_simple:
            # ์‰ฌ์šด ํ‘œํ˜„ ๋กœ์ง
            # OpenAI API ํ˜ธ์ถœ์€ ์‹ค์ œ๋กœ ์‹คํ–‰ํ•˜์‹ค ๋•Œ ์ฃผ์„์„ ํ•ด์ œํ•ด์ฃผ์„ธ์š”.
 
            response = openai.ChatCompletion.create(
                model="gpt-3.5-turbo-16k",
                prompt=f"Rewrite the text in simpler terms: {user_text}",
                temperature=0.1,
                max_tokens=200
            )
            simple_text = response['choices'][0]['text']
            simple_text = "์—ฌ๊ธฐ์— ์‰ฌ์šด ํ‘œํ˜„์ด ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค."  # ์˜ˆ์‹œ
            st.write(f"์‰ฌ์šด ํ‘œํ˜„: {simple_text}")

        if btn_rewrite:
            # ๋‹ค์‹œ ์“ฐ๊ธฐ ๋กœ์ง
            # OpenAI API ํ˜ธ์ถœ์€ ์‹ค์ œ๋กœ ์‹คํ–‰ํ•˜์‹ค ๋•Œ ์ฃผ์„์„ ํ•ด์ œํ•ด์ฃผ์„ธ์š”.
            
            response = openai.ChatCompletion.create(
                model="gpt-3.5-turbo-16k",
                prompt=f"Rewrite the text: {user_text}",
                temperature=0.1,
                max_tokens=200
            )
            rewritten_text = response['choices'][0]['text']
            
            rewritten_text = "์—ฌ๊ธฐ์— ๋‹ค์‹œ ์“ด ํ…์ŠคํŠธ๊ฐ€ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค."  # ์˜ˆ์‹œ
            st.write(f"๋‹ค์‹œ ์“ฐ๊ธฐ: {rewritten_text}")

if __name__ == "__main__":
    main()