Pra-tham commited on
Commit
fa5a727
1 Parent(s): ef78f90
Files changed (2) hide show
  1. app.py +4 -4
  2. temp3.py +20 -5
app.py CHANGED
@@ -70,11 +70,11 @@ def majority_vote_with_steps(question, num_iterations=10):
70
  majority_voted_ans = get_majority_vote(all_answers)
71
  if sucess:
72
  print(type_check(majority_voted_ans))
73
- if type_check(expression) == "Polynomial":
74
- plotfile = draw_polynomial_plot(expression)
75
  else:
76
- if os.path.exists("thankyou.png"):
77
- plotfile = "thankyou.png"
78
  else:
79
  plotfile = None
80
 
 
70
  majority_voted_ans = get_majority_vote(all_answers)
71
  if sucess:
72
  print(type_check(majority_voted_ans))
73
+ if type_check(majority_voted_ans) == "Polynomial":
74
+ plotfile = draw_polynomial_plot(majority_voted_ans)
75
  else:
76
+ if os.path.exists("polynomial_plot.png"):
77
+ plotfile = "polynomial_plot.png"
78
  else:
79
  plotfile = None
80
 
temp3.py CHANGED
@@ -2,6 +2,9 @@ import gradio as gr
2
  from codeexecutor import get_majority_vote, type_check, postprocess_completion, draw_polynomial_plot
3
  import re
4
  iterations=4
 
 
 
5
 
6
  # Mock function for generating predictions
7
  def get_prediction(question):
@@ -58,7 +61,7 @@ def majority_vote_with_steps(question, num_iterations=10):
58
  if type_check(expression) == "Polynomial":
59
  plotfile = draw_polynomial_plot(expression)
60
  else:
61
- plotfile = None
62
 
63
  # Find the steps corresponding to the majority voted answer
64
  for i, ans in enumerate(all_answers):
@@ -78,15 +81,27 @@ def chat_interface(history, question):
78
 
79
  # Convert the plot image to base64 for embedding in chat (if plot exists)
80
  if plotfile:
81
- history.append(("MathBot", f"Answer: \n{steps_solution}\n![Polynomial Plot]({plotfile})"))
 
 
 
 
 
 
82
  else:
83
  history.append(("MathBot", f"Answer: \n{steps_solution}"))
84
 
85
- return history # Return None for the image output as it's embedded in the chat
 
 
 
 
 
 
86
 
87
  # Gradio app setup using Blocks
88
- with gr.Blocks() as interface:
89
- chatbot = gr.Chatbot(label="Chat with MathBot", elem_id="chat_history")
90
  math_question = gr.Textbox(label="Your Question", placeholder="Ask a math question...", elem_id="math_question")
91
 
92
  math_question.submit(chat_interface, inputs=[chatbot, math_question], outputs=[chatbot])
 
2
  from codeexecutor import get_majority_vote, type_check, postprocess_completion, draw_polynomial_plot
3
  import re
4
  iterations=4
5
+ import base64
6
+ from io import BytesIO
7
+ # from PIL import Image
8
 
9
  # Mock function for generating predictions
10
  def get_prediction(question):
 
61
  if type_check(expression) == "Polynomial":
62
  plotfile = draw_polynomial_plot(expression)
63
  else:
64
+ plotfile = "polynomial_plot.png"
65
 
66
  # Find the steps corresponding to the majority voted answer
67
  for i, ans in enumerate(all_answers):
 
81
 
82
  # Convert the plot image to base64 for embedding in chat (if plot exists)
83
  if plotfile:
84
+ history.append(("what is the sum of polynomial 2x+3 and 3x?", f"Answer: \n{steps_solution}"))
85
+
86
+ with open(plotfile, "rb") as image_file:
87
+ image_bytes = image_file.read()
88
+ base64_image = base64.b64encode(image_bytes).decode("utf-8")
89
+ image_data = f'<img src="data:image/png;base64,{base64_image}" width="300"/>'
90
+ history.append(("", image_data))
91
  else:
92
  history.append(("MathBot", f"Answer: \n{steps_solution}"))
93
 
94
+ return history
95
+
96
+ css = """
97
+ #math-question-textbox {
98
+ font-size: 24px !important;
99
+ }
100
+ """
101
 
102
  # Gradio app setup using Blocks
103
+ with gr.Blocks(css=css) as interface:
104
+ chatbot = gr.Chatbot(label="Chat with MathBot", elem_id="chat_history",height="70vh")
105
  math_question = gr.Textbox(label="Your Question", placeholder="Ask a math question...", elem_id="math_question")
106
 
107
  math_question.submit(chat_interface, inputs=[chatbot, math_question], outputs=[chatbot])