keyword / app.py
JUNGU's picture
Update app.py
91674d2
raw
history blame
3.98 kB
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()