jpjp9292 commited on
Commit
c0325b0
Β·
verified Β·
1 Parent(s): 940fafa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from g4f.client import Client
3
+
4
+ # GPT-4o-mini ν΄λΌμ΄μ–ΈνŠΈ μ΄ˆκΈ°ν™”
5
+ client = Client()
6
+
7
+ # νŽ˜μ΄μ§€ μ„€μ •: 제λͺ©, μ•„μ΄μ½˜, λ ˆμ΄μ•„μ›ƒ μ„€μ •
8
+ st.set_page_config(
9
+ page_title="GPT-4o Chat",
10
+ page_icon="πŸ“",
11
+ layout="centered"
12
+ )
13
+
14
+ # μ„Έμ…˜ μƒνƒœ μ΄ˆκΈ°ν™”: μ±„νŒ… 기둝 μ €μž₯
15
+ if "chat_history" not in st.session_state:
16
+ st.session_state.chat_history = []
17
+
18
+ # μ•± 제λͺ© ν‘œμ‹œ
19
+ st.title("GPT-4o-mini Chat πŸ€–")
20
+
21
+ # μ±„νŒ… λ©”μ‹œμ§€ UI 좜λ ₯
22
+ for message in st.session_state.chat_history:
23
+ with st.chat_message(message['role']):
24
+ # μ‚¬μš©μž λ˜λŠ” GPT의 λ©”μ‹œμ§€λ₯Ό ꡬ뢄해 좜λ ₯
25
+ st.markdown(message['content'])
26
+
27
+ # μ‚¬μš©μž μž…λ ₯ μ°½
28
+ user_prompt = st.chat_input("GPT-4o-miniμ—κ²Œ μ§ˆλ¬Έν•΄λ³΄μ„Έμš”!")
29
+
30
+ if user_prompt:
31
+ # μ‚¬μš©μžμ˜ μž…λ ₯ λ©”μ‹œμ§€λ₯Ό UI에 ν‘œμ‹œν•˜κ³  μ„Έμ…˜ μƒνƒœμ— μ €μž₯
32
+ st.chat_message("user").markdown(user_prompt)
33
+ st.session_state.chat_history.append({"role": "user", "content": user_prompt})
34
+
35
+ # GPT-4o-mini λͺ¨λΈμ—κ²Œ λ©”μ‹œμ§€ 전달 및 응닡 생성
36
+ response = client.chat.completions.create(
37
+ model="gpt-4o-mini",
38
+ messages=[
39
+ {"role": "system", "content": "You are a helpful assistant"}, # μ‹œμŠ€ν…œ ν”„λ‘¬ν”„νŠΈ
40
+ *st.session_state.chat_history # 이전 λŒ€ν™” λ‚΄μš© 포함
41
+ ]
42
+ )
43
+
44
+ # GPT 응닡 κ°€μ Έμ˜€κΈ°
45
+ final_response = response.choices[0].message.content
46
+
47
+ # GPT 응닡을 UI에 ν‘œμ‹œν•˜κ³  μ„Έμ…˜ μƒνƒœμ— μ €μž₯
48
+ st.session_state.chat_history.append({"role": "assistant", "content": final_response})
49
+ with st.chat_message("assistant"):
50
+ st.markdown(final_response)