Spaces:
Runtime error
Runtime error
Update page1.py
Browse files
page1.py
CHANGED
@@ -1,195 +1,16 @@
|
|
1 |
import streamlit as st
|
2 |
-
from langchain_core.messages import HumanMessage
|
3 |
-
from langchain_google_genai import ChatGoogleGenerativeAI
|
4 |
-
from langchain.chains import LLMChain
|
5 |
-
from langchain.prompts import PromptTemplate
|
6 |
-
from langchain.memory import ConversationBufferMemory
|
7 |
-
from langchain.memory.chat_message_histories import StreamlitChatMessageHistory
|
8 |
-
from streamlit_chat import message
|
9 |
import time
|
10 |
import random
|
11 |
import os
|
12 |
-
api = os.environ.get("api_key")
|
13 |
|
14 |
def text():
|
|
|
15 |
st.markdown("""
|
16 |
-
|
17 |
-
|
18 |
-
animation: typewriter 3s steps(40) 1s 1 normal both, blinkTextCursor 800ms steps(40) infinite normal;
|
19 |
-
overflow: hidden;
|
20 |
-
white-space: nowrap;
|
21 |
-
border-right: 3px solid;
|
22 |
-
font-family: serif;
|
23 |
-
font-size: 0.9em;
|
24 |
-
}
|
25 |
-
@keyframes typewriter {
|
26 |
-
from {
|
27 |
-
width: 0;
|
28 |
-
}
|
29 |
-
to {
|
30 |
-
width: 100%;
|
31 |
-
height: 100%
|
32 |
-
}
|
33 |
-
}
|
34 |
-
@keyframes blinkTextCursor {
|
35 |
-
from {
|
36 |
-
border-right-color: rgba(255, 255, 255, 0.75);
|
37 |
-
}
|
38 |
-
to {
|
39 |
-
border-right-color: transparent;
|
40 |
-
}
|
41 |
-
}
|
42 |
-
</style>
|
43 |
-
""", unsafe_allow_html=True)
|
44 |
-
text ="Hello 👋, how may I assist you today?"
|
45 |
-
animated_output = f'<div class="line-1 anim-typewriter">{text}</div>'
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
apiKey = api
|
50 |
-
msgs = StreamlitChatMessageHistory(key="special_app_key")
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
msgs.add_ai_message("How can I help you?")
|
55 |
-
template = """You are an AI chatbot having a conversation with a human.
|
56 |
-
|
57 |
-
{history}
|
58 |
-
Human: {human_input}
|
59 |
-
AI: """
|
60 |
-
prompt = PromptTemplate(input_variables=["history", "human_input"], template=template)
|
61 |
-
llm_chain = LLMChain( llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=apiKey), prompt=prompt, memory = memory)
|
62 |
-
|
63 |
-
if 'messages' not in st.session_state:
|
64 |
-
st.session_state['messages'] = []
|
65 |
-
|
66 |
-
for message in st.session_state.messages:
|
67 |
-
with st.chat_message(message["role"]):
|
68 |
-
st.markdown(message["content"])
|
69 |
-
|
70 |
-
prompt = st.chat_input("Say something")
|
71 |
-
|
72 |
-
if prompt:
|
73 |
-
with st.chat_message("user").markdown(prompt):
|
74 |
-
st.session_state.messages.append(
|
75 |
-
{
|
76 |
-
"role": "user",
|
77 |
-
"content": prompt
|
78 |
-
}
|
79 |
-
)
|
80 |
-
# Custom HTML and CSS for three-dot animation
|
81 |
-
spinner_html = """
|
82 |
-
<div class="col-3">
|
83 |
-
<div class="snippet" data-title="dot-pulse">
|
84 |
-
<div class="stage">
|
85 |
-
<div class="dot-pulse"></div>
|
86 |
-
</div>
|
87 |
-
</div>
|
88 |
-
</div>
|
89 |
-
"""
|
90 |
-
|
91 |
-
spinner_css = """
|
92 |
-
.dot-pulse {
|
93 |
-
position: relative;
|
94 |
-
left: -9999px;
|
95 |
-
|
96 |
-
width: 10px;
|
97 |
-
height: 10px;
|
98 |
-
border-radius: 5px;
|
99 |
-
background-color: #9880ff;
|
100 |
-
color: #9880ff;
|
101 |
-
box-shadow: 9999px 0 0 -5px;
|
102 |
-
animation: dot-pulse 1.5s infinite linear;
|
103 |
-
animation-delay: 0.25s;
|
104 |
-
}
|
105 |
-
.dot-pulse::before, .dot-pulse::after {
|
106 |
-
content: "";
|
107 |
-
display: inline-block;
|
108 |
-
position: absolute;
|
109 |
-
top: 0;
|
110 |
-
width: 10px;
|
111 |
-
height: 10px;
|
112 |
-
border-radius: 5px;
|
113 |
-
background-color: #9880ff;
|
114 |
-
color: #9880ff;
|
115 |
-
}
|
116 |
-
.dot-pulse::before {
|
117 |
-
box-shadow: 9984px 0 0 -5px;
|
118 |
-
animation: dot-pulse-before 1.5s infinite linear;
|
119 |
-
animation-delay: 0s;
|
120 |
-
}
|
121 |
-
.dot-pulse::after {
|
122 |
-
box-shadow: 10014px 0 0 -5px;
|
123 |
-
animation: dot-pulse-after 1.5s infinite linear;
|
124 |
-
animation-delay: 0.5s;
|
125 |
-
}
|
126 |
-
|
127 |
-
@keyframes dot-pulse-before {
|
128 |
-
0% {
|
129 |
-
box-shadow: 9984px 0 0 -5px;
|
130 |
-
}
|
131 |
-
30% {
|
132 |
-
box-shadow: 9984px 0 0 2px;
|
133 |
-
}
|
134 |
-
60%, 100% {
|
135 |
-
box-shadow: 9984px 0 0 -5px;
|
136 |
-
}
|
137 |
-
}
|
138 |
-
@keyframes dot-pulse {
|
139 |
-
0% {
|
140 |
-
box-shadow: 9999px 0 0 -5px;
|
141 |
-
}
|
142 |
-
30% {
|
143 |
-
box-shadow: 9999px 0 0 2px;
|
144 |
-
}
|
145 |
-
60%, 100% {
|
146 |
-
box-shadow: 9999px 0 0 -5px;
|
147 |
-
}
|
148 |
-
}
|
149 |
-
@keyframes dot-pulse-after {
|
150 |
-
0% {
|
151 |
-
box-shadow: 10014px 0 0 -5px;
|
152 |
-
}
|
153 |
-
30% {
|
154 |
-
box-shadow: 10014px 0 0 2px;
|
155 |
-
}
|
156 |
-
60%, 100% {
|
157 |
-
box-shadow: 10014px 0 0 -5px;
|
158 |
-
}
|
159 |
-
}
|
160 |
-
"""
|
161 |
-
|
162 |
-
st.markdown(f'<style>{spinner_css}</style>', unsafe_allow_html=True)
|
163 |
-
st.markdown(spinner_html, unsafe_allow_html=True)
|
164 |
-
|
165 |
-
for chunk in llm_chain.stream(prompt):
|
166 |
-
text_output = chunk.get("text", "")
|
167 |
-
st.markdown('<style>.dot-pulse { visibility: hidden; }</style>', unsafe_allow_html=True)
|
168 |
-
|
169 |
-
with st.chat_message("assistant").markdown(text_output):
|
170 |
-
st.session_state.messages.append(
|
171 |
-
{
|
172 |
-
"role": "assistant",
|
173 |
-
"content": text_output
|
174 |
-
}
|
175 |
-
)
|
176 |
-
|
177 |
-
#with st.chat_message("assistant"):
|
178 |
-
#message_placeholder = st.empty()
|
179 |
-
#full_response = ""
|
180 |
-
#assistant_response = random.choice(
|
181 |
-
#[
|
182 |
-
#"Hello there! How can I assist you today?",
|
183 |
-
#"Hi, human! Is there anything I can help you with?",
|
184 |
-
# "Do you need help?",
|
185 |
-
# ]
|
186 |
-
# )
|
187 |
-
# Simulate stream of response with milliseconds delay
|
188 |
-
# for chunk in text_output.split():
|
189 |
-
# full_response += chunk + " "
|
190 |
-
# time.sleep(0.05)
|
191 |
-
# Add a blinking cursor to simulate typing
|
192 |
-
# message_placeholder.markdown(full_response + "▌")
|
193 |
-
# message_placeholder.markdown(full_response)
|
194 |
-
# Add assistant response to chat history
|
195 |
-
# st.session_state.messages.append({"role": "assistant", "content": full_response})
|
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import time
|
3 |
import random
|
4 |
import os
|
|
|
5 |
|
6 |
def text():
|
7 |
+
st.title("Home of ForgeStudio")
|
8 |
st.markdown("""
|
9 |
+
## About
|
10 |
+
This is modern webui for new AI types.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
## How to use
|
13 |
+
In the navigate menu there is options of AI types.
|
|
|
|
|
14 |
|
15 |
+
### Build by [@ehristoforu](https://github.com/ehristoforu)
|
16 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|