Aekanun commited on
Commit
ddc67bf
1 Parent(s): 988c093
Files changed (2) hide show
  1. app.py +35 -27
  2. requirements.txt +1 -2
app.py CHANGED
@@ -1,33 +1,41 @@
1
- import subprocess
2
  import sys
 
3
 
4
  def install_packages():
 
5
  subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', 'pip'])
6
- with open('requirements.txt') as f:
7
- packages = f.read().splitlines()
8
- for package in packages:
9
- if package and not package.startswith('#'):
10
- subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
 
 
11
 
12
  if __name__ == "__main__":
13
- print("Installing required packages...")
14
- install_packages()
15
-
16
- import gradio as gr
17
- import torch
18
- from transformers import AutoProcessor
19
-
20
- def process_handwriting(image):
21
- if image is None:
22
- return "กรุณาอัพโหลดรูปภาพ"
23
- return f"ทดสอบระบบ: Torch version: {torch.__version__}, Transformers installed"
24
-
25
- demo = gr.Interface(
26
- fn=process_handwriting,
27
- inputs=gr.Image(type="pil", label="อัพโหลดรูปภาพ"),
28
- outputs=gr.Textbox(label="ผลลัพธ์"),
29
- title="Test Installation",
30
- description="ทดสอบการติดตั้ง libraries"
31
- )
32
-
33
- demo.launch()
 
 
 
 
 
1
+ import os
2
  import sys
3
+ import subprocess
4
 
5
  def install_packages():
6
+ print("Installing packages...")
7
  subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', 'pip'])
8
+ subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'huggingface_hub'])
9
+ subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'transformers'])
10
+ subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'torch', '--index-url', 'https://download.pytorch.org/whl/cpu'])
11
+ subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'gradio'])
12
+ subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'Pillow'])
13
+ subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'bitsandbytes'])
14
+ subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'accelerate'])
15
 
16
  if __name__ == "__main__":
17
+ try:
18
+ install_packages()
19
+ print("Package installation completed")
20
+
21
+ import gradio as gr
22
+ import torch
23
+ from transformers import AutoProcessor
24
+
25
+ def process_handwriting(image):
26
+ if image is None:
27
+ return "กรุณาอัพโหลดรูปภาพ"
28
+ return f"ทดสอบระบบ: Torch version: {torch.__version__}, Transformers installed"
29
+
30
+ demo = gr.Interface(
31
+ fn=process_handwriting,
32
+ inputs=gr.Image(type="pil", label="อัพโหลดรูปภาพ"),
33
+ outputs=gr.Textbox(label="ผลลัพธ์"),
34
+ title="Test Installation",
35
+ description="ทดสอบการติดตั้ง libraries"
36
+ )
37
+
38
+ demo.launch()
39
+ except Exception as e:
40
+ print(f"Error occurred: {str(e)}")
41
+ raise e
requirements.txt CHANGED
@@ -1,7 +1,6 @@
1
- --extra-index-url https://download.pytorch.org/whl/cpu
2
  huggingface_hub
3
  transformers
4
- torch
5
  gradio
6
  Pillow
7
  bitsandbytes
 
 
1
  huggingface_hub
2
  transformers
3
+ torch --index-url https://download.pytorch.org/whl/cpu
4
  gradio
5
  Pillow
6
  bitsandbytes