File size: 1,773 Bytes
592ad8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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