umerfarooq29 commited on
Commit
c3393f9
·
verified ·
1 Parent(s): bf7e32c

Rename chatbot for calculations to app.py

Browse files
Files changed (1) hide show
  1. chatbot for calculations → app.py +15 -11
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
- def main():
26
- print("Welcome to the Calculator Chatbot! Type 'exit' to end the conversation.")
27
- while True:
28
- user_input = input("You: ")
29
- if user_input.lower() == 'exit':
30
- print("Chatbot: Goodbye!")
31
- break
 
 
 
32
  response = chatbot_response(user_input)
33
- print(f"Chatbot: {response}")
 
 
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