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