Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,10 +25,11 @@ ocr_model = AutoModelForCausalLM.from_pretrained(
|
|
| 25 |
)
|
| 26 |
print("Tải xong mô hình OCR.")
|
| 27 |
|
| 28 |
-
# 2. DÙNG CTRANSFORMERS ĐỂ TẢI GGUF
|
| 29 |
print("Đang tải mô hình LLM (Llama-3-8B GGUF for CPU)...")
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
llm = CAutoModelForCausalLM.from_pretrained(
|
| 33 |
llm_model_id,
|
| 34 |
model_file=llm_model_file,
|
|
@@ -45,7 +46,6 @@ def run_ocr(image: Image.Image) -> str:
|
|
| 45 |
if image is None: return "Lỗi: Vui lòng cung cấp hình ảnh."
|
| 46 |
prompt = "<OCR>"
|
| 47 |
inputs = ocr_processor(text=prompt, images=image, return_tensors="pt").to(device)
|
| 48 |
-
# SỬA LỖI ĐÁNH MÁY Ở ĐÂY
|
| 49 |
generated_ids = ocr_model.generate(
|
| 50 |
input_ids=inputs["input_ids"],
|
| 51 |
pixel_values=inputs["pixel_values"],
|
|
@@ -86,7 +86,7 @@ def create_excel_file(order_data: dict):
|
|
| 86 |
df = pd.DataFrame(flat_data)
|
| 87 |
output = io.BytesIO()
|
| 88 |
with pd.ExcelWriter(output, engine='openpyxl') as writer: df.to_excel(writer, index=False, sheet_name='DonHang')
|
| 89 |
-
timestamp = datetime.now().strftime("%
|
| 90 |
filename = f"don_hang_{timestamp}.xlsx"
|
| 91 |
return (filename, output.getvalue())
|
| 92 |
|
|
|
|
| 25 |
)
|
| 26 |
print("Tải xong mô hình OCR.")
|
| 27 |
|
| 28 |
+
# 2. DÙNG CTRANSFORMERS ĐỂ TẢI GGUF (ĐỔI NHÀ CUNG CẤP)
|
| 29 |
print("Đang tải mô hình LLM (Llama-3-8B GGUF for CPU)...")
|
| 30 |
+
# SỬ DỤNG PHIÊN BẢN GGUF TỪ MỘT NHÀ CUNG CẤP KHÁC
|
| 31 |
+
llm_model_id = "bartowski/Meta-Llama-3-8B-Instruct-GGUF"
|
| 32 |
+
llm_model_file = "Meta-Llama-3-8B-Instruct-Q4_K_M.gguf"
|
| 33 |
llm = CAutoModelForCausalLM.from_pretrained(
|
| 34 |
llm_model_id,
|
| 35 |
model_file=llm_model_file,
|
|
|
|
| 46 |
if image is None: return "Lỗi: Vui lòng cung cấp hình ảnh."
|
| 47 |
prompt = "<OCR>"
|
| 48 |
inputs = ocr_processor(text=prompt, images=image, return_tensors="pt").to(device)
|
|
|
|
| 49 |
generated_ids = ocr_model.generate(
|
| 50 |
input_ids=inputs["input_ids"],
|
| 51 |
pixel_values=inputs["pixel_values"],
|
|
|
|
| 86 |
df = pd.DataFrame(flat_data)
|
| 87 |
output = io.BytesIO()
|
| 88 |
with pd.ExcelWriter(output, engine='openpyxl') as writer: df.to_excel(writer, index=False, sheet_name='DonHang')
|
| 89 |
+
timestamp = datetime.now().strftime("%Ym%d_%H%M%S")
|
| 90 |
filename = f"don_hang_{timestamp}.xlsx"
|
| 91 |
return (filename, output.getvalue())
|
| 92 |
|