Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
import ctranslate2
|
4 |
from transformers import AutoTokenizer
|
@@ -29,8 +28,7 @@ def get_prediction(question):
|
|
29 |
|
30 |
# Function to parse the prediction to extract the answer and steps
|
31 |
def parse_prediction(prediction):
|
32 |
-
lines = prediction.strip().split('
|
33 |
-
')
|
34 |
answer = None
|
35 |
steps = []
|
36 |
for line in lines:
|
@@ -44,8 +42,7 @@ def parse_prediction(prediction):
|
|
44 |
# If no "Answer:" found, assume last line is the answer
|
45 |
answer = lines[-1].strip()
|
46 |
steps = lines[:-1]
|
47 |
-
steps_text = '
|
48 |
-
'.join(steps).strip()
|
49 |
return answer, steps_text
|
50 |
|
51 |
# Function to perform majority voting and get steps
|
@@ -85,7 +82,93 @@ def gradio_interface(question, correct_answer):
|
|
85 |
}
|
86 |
|
87 |
# Custom CSS for enhanced design (unchanged)
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
# Gradio app setup
|
91 |
interface = gr.Interface(
|
@@ -99,11 +182,8 @@ interface = gr.Interface(
|
|
99 |
],
|
100 |
title="🔢 Math Question Solver",
|
101 |
description="Enter a math question to get the model's majority-voted answer and steps to solve the problem.",
|
102 |
-
|
103 |
)
|
104 |
|
105 |
if __name__ == "__main__":
|
106 |
interface.launch()
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import ctranslate2
|
3 |
from transformers import AutoTokenizer
|
|
|
28 |
|
29 |
# Function to parse the prediction to extract the answer and steps
|
30 |
def parse_prediction(prediction):
|
31 |
+
lines = prediction.strip().split('\n')
|
|
|
32 |
answer = None
|
33 |
steps = []
|
34 |
for line in lines:
|
|
|
42 |
# If no "Answer:" found, assume last line is the answer
|
43 |
answer = lines[-1].strip()
|
44 |
steps = lines[:-1]
|
45 |
+
steps_text = '\n'.join(steps).strip()
|
|
|
46 |
return answer, steps_text
|
47 |
|
48 |
# Function to perform majority voting and get steps
|
|
|
82 |
}
|
83 |
|
84 |
# Custom CSS for enhanced design (unchanged)
|
85 |
+
custom_css = """
|
86 |
+
body {
|
87 |
+
background-color: #fafafa;
|
88 |
+
font-family: 'Open Sans', sans-serif;
|
89 |
+
}
|
90 |
+
.gradio-container {
|
91 |
+
background-color: #ffffff;
|
92 |
+
border: 3px solid #007acc;
|
93 |
+
border-radius: 15px;
|
94 |
+
padding: 20px;
|
95 |
+
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
|
96 |
+
max-width: 800px;
|
97 |
+
margin: 50px auto;
|
98 |
+
}
|
99 |
+
h1 {
|
100 |
+
font-family: 'Poppins', sans-serif;
|
101 |
+
color: #007acc;
|
102 |
+
font-weight: bold;
|
103 |
+
font-size: 32px;
|
104 |
+
text-align: center;
|
105 |
+
margin-bottom: 20px;
|
106 |
+
}
|
107 |
+
p {
|
108 |
+
font-family: 'Roboto', sans-serif;
|
109 |
+
font-size: 18px;
|
110 |
+
color: #333;
|
111 |
+
text-align: center;
|
112 |
+
margin-bottom: 15px;
|
113 |
+
}
|
114 |
+
input, textarea {
|
115 |
+
font-family: 'Montserrat', sans-serif;
|
116 |
+
font-size: 16px;
|
117 |
+
padding: 10px;
|
118 |
+
border: 2px solid #007acc;
|
119 |
+
border-radius: 10px;
|
120 |
+
background-color: #f1f8ff;
|
121 |
+
margin-bottom: 15px;
|
122 |
+
}
|
123 |
+
#math_question, #correct_answer {
|
124 |
+
font-size: 20px;
|
125 |
+
font-family: 'Poppins', sans-serif;
|
126 |
+
font-weight: 500px;
|
127 |
+
color: #007acc;
|
128 |
+
margin-bottom: 5px;
|
129 |
+
display: inline-block;
|
130 |
+
}
|
131 |
+
|
132 |
+
textarea {
|
133 |
+
min-height: 150px;
|
134 |
+
}
|
135 |
+
.gr-button-primary {
|
136 |
+
background-color: #007acc !important;
|
137 |
+
color: white !important;
|
138 |
+
border-radius: 10px !important;
|
139 |
+
font-size: 18px !important;
|
140 |
+
font-weight: bold !important;
|
141 |
+
padding: 10px 20px !important;
|
142 |
+
font-family: 'Montserrat', sans-serif !important;
|
143 |
+
transition: background-color 0.3s ease !important;
|
144 |
+
}
|
145 |
+
.gr-button-primary:hover {
|
146 |
+
background-color: #005f99 !important;
|
147 |
+
}
|
148 |
+
.gr-button-secondary {
|
149 |
+
background-color: #f44336 !important;
|
150 |
+
color: white !important;
|
151 |
+
border-radius: 10px !important;
|
152 |
+
font-size: 18px !important;
|
153 |
+
font-weight: bold !important;
|
154 |
+
padding: 10px 20px !important;
|
155 |
+
font-family: 'Montserrat', sans-serif !important;
|
156 |
+
transition: background-color 0.3s ease !important;
|
157 |
+
}
|
158 |
+
.gr-button-secondary:hover {
|
159 |
+
background-color: #c62828 !important;
|
160 |
+
}
|
161 |
+
.gr-output {
|
162 |
+
background-color: #e0f7fa;
|
163 |
+
border: 2px solid #007acc;
|
164 |
+
border-radius: 10px;
|
165 |
+
padding: 15px;
|
166 |
+
font-size: 16px;
|
167 |
+
font-family: 'Roboto', sans-serif;
|
168 |
+
font-weight: bold;
|
169 |
+
color: #00796b;
|
170 |
+
}
|
171 |
+
"""
|
172 |
|
173 |
# Gradio app setup
|
174 |
interface = gr.Interface(
|
|
|
182 |
],
|
183 |
title="🔢 Math Question Solver",
|
184 |
description="Enter a math question to get the model's majority-voted answer and steps to solve the problem.",
|
185 |
+
css=custom_css # Apply custom CSS
|
186 |
)
|
187 |
|
188 |
if __name__ == "__main__":
|
189 |
interface.launch()
|
|
|
|
|
|