-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
53 lines (43 loc) · 1.73 KB
/
app.py
File metadata and controls
53 lines (43 loc) · 1.73 KB
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
import streamlit as st
from front.layout import render_layout
from front.sidebar import render_sidebar
from front.main_page import render_main_page
from front.right_sidebar import render_right_sidebar
from back.chat_storage import initialize_chat_storage, load_chat_history
from back.llm_service import initialize_model
import torch
import gc
# Streamlit 페이지 설정
st.set_page_config(page_title="Prompt Explainer", layout="wide", page_icon="🧑💼")
# 대화 기록 파일 초기화
initialize_chat_storage()
# 상태 변수 초기화
if "chat_history" not in st.session_state:
st.session_state["chat_history"] = load_chat_history()
if "messages" not in st.session_state:
st.session_state["messages"] = [] # 현재 대화 기록
if "current_page" not in st.session_state:
st.session_state["current_page"] = 1 # 기본 페이지 번호
if "current_prompt" not in st.session_state:
st.session_state["current_prompt"] = None # 기본 시스템 프롬프트 없음
if "model" not in st.session_state:
st.session_state["model"] = initialize_model("Qwen/Qwen2.5-1.5B-Instruct") # 올바른 모델 초기화
if "greetings" not in st.session_state:
st.session_state["greetings"] = False # 초기 상태는 False로 설정
# GPU 메모리 및 캐시 초기화 함수
def clear_gpu_cache():
if torch.cuda.is_available():
torch.cuda.empty_cache()
gc.collect()
# 레이아웃 정의: 중앙(8), 오른쪽(3) 비율
col2, col3 = render_layout()
# 왼쪽 사이드바
render_sidebar()
# 중앙 메인 페이지
with col2:
st.title("Prompt Explainer")
clear_gpu_cache() # 매번 렌더링 시 GPU 캐시 초기화
render_main_page()
# 오른쪽 사이드바
with col3:
render_right_sidebar()