Spaces:
Sleeping
Sleeping
Rollback to not using forms
Browse files
app.py
CHANGED
|
@@ -43,41 +43,37 @@ st.markdown(
|
|
| 43 |
)
|
| 44 |
|
| 45 |
# Define the placeholder globally (outside columns)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
placeholder.markdown(f'<div class="scrollable-div"><p>Welcome! I am your Adrega AI assistant</p></div>', unsafe_allow_html=True)
|
| 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 |
-
submitted = st.form_submit_button("Ask")
|
| 82 |
-
if (submitted):
|
| 83 |
-
handle_submit()
|
|
|
|
| 43 |
)
|
| 44 |
|
| 45 |
# Define the placeholder globally (outside columns)
|
| 46 |
+
placeholder = st.empty()
|
| 47 |
+
placeholder.markdown(f'<div class="scrollable-div"><p>Welcome! I am your Adrega AI assistant</p></div>', unsafe_allow_html=True)
|
|
|
|
| 48 |
|
| 49 |
+
def handle_submit():
|
| 50 |
+
user_input = st.session_state.user_input
|
| 51 |
+
|
| 52 |
+
if user_input:
|
| 53 |
+
messages = [
|
| 54 |
+
{"role": "system", "content": f"Context: {context}"},
|
| 55 |
+
{"role": "user", "content": user_input}
|
| 56 |
+
]
|
| 57 |
+
|
| 58 |
+
response = client.chat.completions.create(
|
| 59 |
+
model="Qwen/Qwen2.5-72B-Instruct",
|
| 60 |
+
messages=messages,
|
| 61 |
+
max_tokens=1000,
|
| 62 |
+
stream=True
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
answer = ""
|
| 66 |
+
|
| 67 |
+
for chunk in response:
|
| 68 |
+
answer += chunk['choices'][0]['delta']['content']
|
| 69 |
+
placeholder.markdown(f'<div class="scrollable-div"><p>{answer}</p></div>', unsafe_allow_html=True)
|
| 70 |
+
|
| 71 |
+
st.session_state.conversation = f"<p>{answer}</p>";
|
| 72 |
+
placeholder.markdown(f'<div class="scrollable-div">{st.session_state.conversation}</div>', unsafe_allow_html=True)
|
| 73 |
+
#else:
|
| 74 |
+
#st.session_state.conversation(f"<p><strong>Adrega AI:</strong>: Please enter a question.")
|
| 75 |
+
|
| 76 |
+
st.text_input('Ask me a question', key='user_input', on_change=handle_submit)
|
| 77 |
+
|
| 78 |
+
if st.button("Ask"):
|
| 79 |
+
handle_submit()
|
|
|
|
|
|
|
|
|