Spaces:
Runtime error
Runtime error
shohabbosdev
commited on
Commit
•
21a63c5
1
Parent(s):
0f3ad15
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sympy as sp
|
2 |
+
import matplotlib.pyplot as plt
|
3 |
+
import gradio as gr
|
4 |
+
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 |
+
|
31 |
+
# Gradio interfaysini yaratish
|
32 |
+
with gr.Blocks(theme="gradio/seafoam") as demo:
|
33 |
+
gr.Markdown("""# Istalgan Matematik Formulalar
|
34 |
+
Barchasi juda oson shunchaki matn kiriting va uning matematik ifodasini latex formatda va rasm holatda yuklab oling
|
35 |
+
""")
|
36 |
+
with gr.Accordion(label="Dastur haqida qisqacha", open=False):
|
37 |
+
gr.Markdown("""# Bundan foydalanish juda oson!!!
|
38 |
+
Buning uchun siz python dasturini hamda <code>gradio</code>, <code>matplotlib</code>, <code>sympy</code> kabi kutubxonalar o'rnatasiz<br>
|
39 |
+
Hurmat bilan <a href="https://t.me/shohabbosde">Shoh Abbos Ulug'murodov</a>
|
40 |
+
""")
|
41 |
+
with gr.Row():
|
42 |
+
formula_input = gr.Textbox(label="Matematik formula kiritish qismi", placeholder="Formulani kiriting...", autofocus=True)
|
43 |
+
with gr.Row():
|
44 |
+
latex_output = gr.Textbox(label="LaTeX formatdagi formulasi", info="LaTeX formatdagi formula shu qismda ko'rinadi", show_copy_button=True)
|
45 |
+
image_output = gr.Image(label="Formula tasviri", elem_id="formula_image", show_share_button=True)
|
46 |
+
|
47 |
+
formula_input.change(fn=generate_math_formula_image, inputs=formula_input, outputs=[latex_output, image_output])
|
48 |
+
|
49 |
+
if __name__ == "__main__":
|
50 |
+
demo.launch()
|