-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
119 lines (104 loc) · 3.12 KB
/
app.py
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import streamlit as st
from llm_utils.graph import builder
from langchain_core.messages import HumanMessage
from streamlit.components.v1 import html
st.set_page_config(page_title="🍔 맛집 추천 서비스", layout="wide")
st.title("🍔 맛집 추천 서비스")
my_html = """
<style>
#log {
font-family: Arial, sans-serif;
color: white; /* 무난한 색상 */
display:flex;
align-items: center;
}
.spinner {
margin-right:10px;
transform: translateY(-50%);
border: 4px solid #f3f3f3; /* Light grey */
border-top: 4px solid #3498db; /* Blue */
border-radius: 50%;
width: 20px;
height: 20px;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
<script>
function logResponses() {
var logContainer = document.querySelector('#log');
setInterval(function () {
fetch('http://34.16.215.193:9999')
.then(response => response.text())
.then(data => {
if (data !== '""') {
logContainer.innerHTML = '<div class="spinner"></div>'; // Clear the container and add spinner
var logEntry = document.createElement('div');
logEntry.textContent = data.replaceAll('"', "");
logContainer.appendChild(logEntry);
}
else {
// clear
logContainer.innerHTML = '';
}
})
.catch(error => {
var logEntry = document.createElement('div');
logEntry.textContent = 'Error: ' + error;
logContainer.appendChild(logEntry);
});
}, 1000); // Send request every second
}
window.onload = function () {
logResponses();
};
</script>
<body>
<div id="log">
</div>
</body>
"""
if "responses" not in st.session_state:
st.session_state.responses = []
st.write("### Responses")
response_container = st.container()
for response in st.session_state.responses:
with response_container:
st.text(response)
html(my_html, height=50)
col1, col2 = st.columns([4, 1])
with col1:
input_text = st.text_input("Enter your query:", key="input_text")
with col2:
if st.button("Submit"):
graph = builder.compile()
if input_text:
st.session_state.responses = []
human_message = HumanMessage(content=input_text)
res = graph.invoke(input=human_message)
response = f"""
질문: {input_text}\n
{res[-1].content}
"""
response = response.replace(" ", "")
print("-" * 100)
print(response)
print("-" * 100)
st.session_state.responses.append(response)
st.rerun()
st.markdown(
"""
<style>
.stTextInput, .stButton {
margin-bottom: 0 !important;
}
.stButton {
margin-top: 30px;
}
</style>
""",
unsafe_allow_html=True,
)