Spaces:
Running
on
Zero
Running
on
Zero
fix
Browse files- app.py +35 -27
- requirements.txt +1 -2
app.py
CHANGED
@@ -1,33 +1,41 @@
|
|
1 |
-
import
|
2 |
import sys
|
|
|
3 |
|
4 |
def install_packages():
|
|
|
5 |
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', 'pip'])
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
|
12 |
if __name__ == "__main__":
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
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
|