Update app.py
Browse files
app.py
CHANGED
|
@@ -41,16 +41,22 @@ def main():
|
|
| 41 |
topic = st.selectbox("Choose a programming topic", developer_topics)
|
| 42 |
user_input = st.text_area("Or ask a programming-related question:", "")
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
| 56 |
main()
|
|
|
|
| 41 |
topic = st.selectbox("Choose a programming topic", developer_topics)
|
| 42 |
user_input = st.text_area("Or ask a programming-related question:", "")
|
| 43 |
|
| 44 |
+
# Add a submit button to trigger the response
|
| 45 |
+
submit_button = st.button("Submit")
|
| 46 |
+
|
| 47 |
+
# If the user clicks the submit button, process the query
|
| 48 |
+
if submit_button:
|
| 49 |
+
if user_input:
|
| 50 |
+
query = user_input
|
| 51 |
+
# Check if the user input is related to a programming topic
|
| 52 |
+
if any(topic.lower() in user_input.lower() for topic in developer_topics):
|
| 53 |
+
response = get_response(query)
|
| 54 |
+
st.write("### Response:")
|
| 55 |
+
st.write(response)
|
| 56 |
+
else:
|
| 57 |
+
st.write("Sorry, I can only answer programming-related questions.")
|
| 58 |
+
else:
|
| 59 |
+
st.write("Please enter a programming-related question or choose a topic.")
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
| 62 |
main()
|