Spaces:
Runtime error
Runtime error
update transformers
Browse files- app.py +12 -24
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
-
import
|
4 |
-
from huggingface_hub import login, HfApi
|
5 |
|
6 |
# Lấy token từ biến môi trường
|
7 |
token = os.getenv("TOKEN")
|
@@ -10,30 +9,19 @@ if token is None:
|
|
10 |
raise ValueError("TOKEN environment variable not set")
|
11 |
|
12 |
# Đăng nhập vào Hugging Face bằng token
|
|
|
13 |
login(token=token)
|
14 |
|
15 |
-
#
|
16 |
-
hf_api = HfApi(token=token)
|
17 |
-
|
18 |
-
# Đảm bảo rằng tên mô hình là chính xác
|
19 |
model_name = "HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1"
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
#
|
22 |
-
|
23 |
-
for i in range(retries):
|
24 |
-
try:
|
25 |
-
demo = gr.load(f"models/{model_name}")
|
26 |
-
return demo
|
27 |
-
except Exception as e:
|
28 |
-
print(f"Error loading model (attempt {i+1}/{retries}): {e}")
|
29 |
-
if i < retries - 1:
|
30 |
-
time.sleep(delay)
|
31 |
-
else:
|
32 |
-
raise
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
demo = load_model_with_retry(model_name)
|
37 |
-
demo.launch()
|
38 |
-
except Exception as e:
|
39 |
-
print(f"Failed to load model after multiple attempts: {e}")
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
+
from transformers import pipeline
|
|
|
4 |
|
5 |
# Lấy token từ biến môi trường
|
6 |
token = os.getenv("TOKEN")
|
|
|
9 |
raise ValueError("TOKEN environment variable not set")
|
10 |
|
11 |
# Đăng nhập vào Hugging Face bằng token
|
12 |
+
from huggingface_hub import login
|
13 |
login(token=token)
|
14 |
|
15 |
+
# Tải mô hình từ Hugging Face Hub
|
|
|
|
|
|
|
16 |
model_name = "HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1"
|
17 |
+
classifier = pipeline("text-classification", model=model_name, token=token)
|
18 |
+
|
19 |
+
# Định nghĩa hàm xử lý
|
20 |
+
def classify_text(text):
|
21 |
+
return classifier(text)
|
22 |
|
23 |
+
# Tạo interface Gradio
|
24 |
+
iface = gr.Interface(fn=classify_text, inputs="text", outputs="label")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
# Khởi chạy ứng dụng
|
27 |
+
iface.launch()
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
huggingface_hub==0.22.2
|
2 |
-
gradio
|
|
|
|
1 |
huggingface_hub==0.22.2
|
2 |
+
gradio
|
3 |
+
transformers
|