Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,42 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from utils import load_material_db,
|
| 3 |
|
| 4 |
-
# بارگذاری
|
| 5 |
material_db = load_material_db()
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
output_lines = ["**کالاهای پیشنهادی:**\n"]
|
| 16 |
-
for item in filtered_items:
|
| 17 |
-
output_lines.append(f"- 📦 {item['item_name']} | 📏 {item['unit']} | 🔢 {item['quantity']} | کد فهرست بها: `{item['item_code']}`")
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
gr.Textbox(label="
|
| 26 |
-
gr.
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
)
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|
| 36 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from utils import load_material_db, save_material_db, build_db_from_excel, get_items_for_description
|
| 3 |
|
| 4 |
+
# بارگذاری دیتابیس موجود (در صورت وجود)
|
| 5 |
material_db = load_material_db()
|
| 6 |
|
| 7 |
+
def upload_excel_and_generate_db(file, description):
|
| 8 |
+
global material_db
|
| 9 |
+
material_db = build_db_from_excel(file.name, description)
|
| 10 |
+
save_material_db(material_db)
|
| 11 |
+
return f"✅ دیتابیس برای توصیف '{description}' با {len(material_db[description])} کالا ذخیره شد."
|
| 12 |
|
| 13 |
+
def analyze_description(description):
|
| 14 |
+
items = get_items_for_description(material_db, description)
|
| 15 |
+
if not items:
|
| 16 |
+
return "❌ برای این توصیف دادهای پیدا نشد. ابتدا فایل مرتبط را آپلود کنید."
|
| 17 |
+
|
| 18 |
+
output = [f"### 📦 براورد برای: {description}\n"]
|
| 19 |
+
for item in items:
|
| 20 |
+
output.append(f"- {item['item_name']} | {item['quantity']} {item['unit']} | کد: {item['item_code']}")
|
| 21 |
+
return "\n".join(output)
|
| 22 |
|
| 23 |
+
demo = gr.Blocks()
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
with demo:
|
| 26 |
+
gr.Markdown("## 📊 ساخت پایگاه داده براساس فایل اکسل + نمایش براورد بر اساس توصیف")
|
| 27 |
+
with gr.Tab("1️⃣ ساخت پایگاه داده"):
|
| 28 |
+
with gr.Row():
|
| 29 |
+
file_input = gr.File(label="آپلود فایل اکسل")
|
| 30 |
+
description_input = gr.Textbox(label="توصیف پروژه", placeholder="مثلاً: نصب کابل زمینی 120")
|
| 31 |
+
db_output = gr.Textbox(label="وضعیت", interactive=False)
|
| 32 |
+
generate_btn = gr.Button("ساخت دیتابیس")
|
| 33 |
+
generate_btn.click(upload_excel_and_generate_db, inputs=[file_input, description_input], outputs=db_output)
|
| 34 |
+
|
| 35 |
+
with gr.Tab("2️⃣ نمایش براورد"):
|
| 36 |
+
description_query = gr.Textbox(label="توصیف پروژه", placeholder="مثلاً: نصب کابل زمینی 120")
|
| 37 |
+
result_output = gr.Markdown()
|
| 38 |
+
search_btn = gr.Button("نمایش کالاها")
|
| 39 |
+
search_btn.click(analyze_description, inputs=description_query, outputs=result_output)
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
| 42 |
demo.launch()
|