Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,26 +5,29 @@ import time
|
|
| 5 |
|
| 6 |
def generate_math_formula_image(formula_str, progress=gr.Progress()):
|
| 7 |
try:
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
return str(e), None
|
| 30 |
|
|
|
|
| 5 |
|
| 6 |
def generate_math_formula_image(formula_str, progress=gr.Progress()):
|
| 7 |
try:
|
| 8 |
+
if formula_str is None:
|
| 9 |
+
return gr.Info("Kiritish maydoni bo'sh bo'lmasligi zarur %s" %formula_str), None
|
| 10 |
+
else:
|
| 11 |
+
progress(0, desc="Formula yaratish jarayoni boshlandi. Bu biroz vaqt olishi mumkin. Iltimos ozgina kuting!!!")
|
| 12 |
+
time.sleep(1)
|
| 13 |
+
# Matematik formulani yaratish
|
| 14 |
+
formula = sp.sympify(formula_str)
|
| 15 |
+
|
| 16 |
+
# Formulani LaTeX formatida ifodalash
|
| 17 |
+
latex_formula = sp.latex(formula)
|
| 18 |
+
|
| 19 |
+
# Formulani rasmga aylantirish
|
| 20 |
+
fig = plt.figure(figsize=(6, 2))
|
| 21 |
+
plt.text(0.5, 0.5, r'$%s$' % latex_formula, fontsize=20, horizontalalignment='center', verticalalignment='center')
|
| 22 |
+
plt.axis('off')
|
| 23 |
+
|
| 24 |
+
# Rasmni saqlab olish
|
| 25 |
+
image_file = 'formula.png'
|
| 26 |
+
plt.savefig(image_file, dpi=300, bbox_inches='tight', pad_inches=0.1)
|
| 27 |
+
plt.close(fig)
|
| 28 |
+
for i in progress.tqdm(range(100)):
|
| 29 |
+
time.sleep(0.01)
|
| 30 |
+
return latex_formula, image_file
|
| 31 |
except Exception as e:
|
| 32 |
return str(e), None
|
| 33 |
|