andreska commited on
Commit
8a56136
·
verified ·
1 Parent(s): a87a225

Try fix blank box #7

Browse files
Files changed (1) hide show
  1. app.py +32 -35
app.py CHANGED
@@ -43,41 +43,38 @@ st.markdown(
43
  )
44
 
45
  # Define the placeholder globally (outside columns)
46
- if('conversation' not in st.session_state):
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
-
82
- #if 'conversation' not in st.session_state:
83
- # st.session_state.conversation = ""
 
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()