Thai-HandWriting-to-Text / app.py.origi
Aekanun's picture
fixed and run app.py
592ad8f
raw
history blame
1.77 kB
import os
import sys
import subprocess
def install_packages():
print("Installing packages...")
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', 'pip'])
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'huggingface_hub'])
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'transformers'])
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'torch', '--index-url', 'https://download.pytorch.org/whl/cpu'])
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'gradio'])
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'Pillow'])
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'bitsandbytes'])
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'accelerate'])
if __name__ == "__main__":
try:
install_packages()
print("Package installation completed")
import gradio as gr
import torch
from transformers import AutoProcessor
def process_handwriting(image):
if image is None:
return "กรุณาอัพโหลดรูปภาพ"
return f"ทดสอบระบบ: Torch version: {torch.__version__}, Transformers installed"
demo = gr.Interface(
fn=process_handwriting,
inputs=gr.Image(type="pil", label="อัพโหลดรูปภาพ"),
outputs=gr.Textbox(label="ผลลัพธ์"),
title="Test Installation",
description="ทดสอบการติดตั้ง libraries"
)
demo.launch()
except Exception as e:
print(f"Error occurred: {str(e)}")
raise e