Spaces:
Sleeping
Sleeping
Rename chatbot for calculations to app.py
Browse files
chatbot for calculations → app.py
RENAMED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# calculator_chatbot.py
|
| 2 |
|
|
|
|
| 3 |
import re
|
| 4 |
|
| 5 |
def evaluate_expression(expression):
|
|
@@ -14,7 +15,7 @@ def chatbot_response(user_input):
|
|
| 14 |
# Regular expression to find mathematical expressions
|
| 15 |
expression_pattern = r'(\d+\s*[\+\-\*\/]\s*\d+)'
|
| 16 |
match = re.search(expression_pattern, user_input)
|
| 17 |
-
|
| 18 |
if match:
|
| 19 |
expression = match.group(0)
|
| 20 |
result = evaluate_expression(expression)
|
|
@@ -22,15 +23,18 @@ def chatbot_response(user_input):
|
|
| 22 |
else:
|
| 23 |
return "I'm sorry, I can only help with simple math calculations."
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
response = chatbot_response(user_input)
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
if __name__ == "__main__":
|
| 36 |
-
main()
|
|
|
|
| 1 |
# calculator_chatbot.py
|
| 2 |
|
| 3 |
+
import streamlit as st
|
| 4 |
import re
|
| 5 |
|
| 6 |
def evaluate_expression(expression):
|
|
|
|
| 15 |
# Regular expression to find mathematical expressions
|
| 16 |
expression_pattern = r'(\d+\s*[\+\-\*\/]\s*\d+)'
|
| 17 |
match = re.search(expression_pattern, user_input)
|
| 18 |
+
|
| 19 |
if match:
|
| 20 |
expression = match.group(0)
|
| 21 |
result = evaluate_expression(expression)
|
|
|
|
| 23 |
else:
|
| 24 |
return "I'm sorry, I can only help with simple math calculations."
|
| 25 |
|
| 26 |
+
# ---------------- Streamlit UI ----------------
|
| 27 |
+
st.title("🧮 Calculator Chatbot")
|
| 28 |
+
st.write("Welcome to the Calculator Chatbot! Type a simple math expression like '2 + 3' or '5 * 4'.")
|
| 29 |
+
|
| 30 |
+
user_input = st.text_input("You:")
|
| 31 |
+
|
| 32 |
+
if user_input:
|
| 33 |
+
if user_input.lower() == 'exit':
|
| 34 |
+
st.write("Chatbot: Goodbye!")
|
| 35 |
+
else:
|
| 36 |
response = chatbot_response(user_input)
|
| 37 |
+
st.success(f"Chatbot: {response}")
|
| 38 |
+
|
| 39 |
+
st.write("\n💡 Example: Try typing '10 / 2' or '6 - 3'")
|
| 40 |
|
|
|
|
|
|