shohabbosdev commited on
Commit
a8fe89e
1 Parent(s): d28776d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -20
app.py CHANGED
@@ -5,26 +5,29 @@ import time
5
 
6
  def generate_math_formula_image(formula_str, progress=gr.Progress()):
7
  try:
8
- progress(0, desc="Formula yaratish jarayoni boshlandi. Bu biroz vaqt olishi mumkin. Iltimos ozgina kuting!!!")
9
- time.sleep(1)
10
- # Matematik formulani yaratish
11
- formula = sp.sympify(formula_str)
12
-
13
- # Formulani LaTeX formatida ifodalash
14
- latex_formula = sp.latex(formula)
15
-
16
- # Formulani rasmga aylantirish
17
- fig = plt.figure(figsize=(6, 2))
18
- plt.text(0.5, 0.5, r'$%s$' % latex_formula, fontsize=20, horizontalalignment='center', verticalalignment='center')
19
- plt.axis('off')
20
-
21
- # Rasmni saqlab olish
22
- image_file = 'formula.png'
23
- plt.savefig(image_file, dpi=300, bbox_inches='tight', pad_inches=0.1)
24
- plt.close(fig)
25
- for i in progress.tqdm(range(100)):
26
- time.sleep(0.01)
27
- return latex_formula, image_file
 
 
 
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