andreska commited on
Commit
94ee0d3
·
verified ·
1 Parent(s): 10453a6

Rollback to not using forms

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