KoiiVN commited on
Commit
5e089eb
·
1 Parent(s): c389cf4

Updated project files

Browse files
GUIDE.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hướng dẫn sử dụng Template HuggingFace Space
2
+ Template này được thiết kế để nhanh chóng xây dựng và triển khai một AIO Gradio demo trên HuggingFace Space.
3
+
4
+ ## Cấu trúc thư mục
5
+ ```
6
+ Folder/
7
+ ├── .gitattributes (HuggingFace tự tạo khi tạo Space)
8
+ ├── app.py
9
+ ├── README.md (HuggingFace tự tạo khi tạo Space)
10
+ ├── requirements.txt
11
+ ├── ui_template.py
12
+ ├── src/
13
+ └── static/
14
+ ```
15
+
16
+ - `app.py`: Đây là file chính để chạy Gradio demo.
17
+ - `requirements.txt`: Liệt kê các thư viện Python cần thiết cho demo.
18
+ - `ui_template.py`: Chứa các hàm và CSS tùy chỉnh để tạo UI cho demo.
19
+ - `src/`: Chứa các code như mô hình.
20
+ - `static/`: Chứa các tài nguyên tĩnh như hình ảnh logo.
21
+
22
+ ## Hướng dẫn sử dụng
23
+ 1. **Cập nhật `src`**:
24
+ * Xây dựng các hàm khởi tạo, định nghĩa mô hình hoặc các hàm liên quan khác.
25
+
26
+ 2. **Cập nhật `app.py`**:
27
+ * Thêm các hàm cần thiết như khởi tạo/gọi mô hình, xử lý đầu vào, ... tại vùng Functions.
28
+ * Có thể thêm các thành phần UI khác vào phần `gr.Blocks` nếu cần.
29
+ * **Quan trọng**: Không thay đổi các dòng liên quan đến `ui_template.create_header()`, `ui_template.create_footer()`, và `demo.launch()`.
30
+
31
+ 3. **Cập nhật `ui_template.py`**:
32
+ * Thay đổi giá trị của biến `PROJECT_NAME` thành tên dự án của bạn.
33
+ * Thay đổi giá trị của biến `AIO_YEAR` và `AIO_MODULE` cho phù hợp với thời điểm hiện tại.
34
+
35
+ 4. **Cập nhật `requirements.txt` và thêm `.gitignore`**:
36
+ * Thêm tất cả các thư viện Python cần thiết cho demo, mỗi thư viện trên một dòng và nên kèm theo phiên bản cụ thể. Ví dụ: `torch==1.0.0`.
37
+ * Tạo thêm file `.gitignore` nếu cần.
38
+
39
+ 5. **Linh hoạt với các file còn lại**
40
+
41
+ 6. **Chạy thử ở local trước khi deploy**
42
+ * Chạy lệnh sau trong Terminal:
43
+ ```
44
+ python Folder/app.py
45
+ ```
46
+
47
+ Hết,
48
+ Koi (last edited: 22/7/2025)
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ import vlai_template # must import
4
+
5
+ # ──────────────────────────── Functions ─────────────────────────
6
+ def inference(*arg):
7
+ return "It worked 🎉🎊"
8
+
9
+ # ... your functions ...
10
+
11
+
12
+ # ──────────────────────────── Main ─────────────────────────
13
+ with gr.Blocks(theme='gstaff/sketch', css=vlai_template.custom_css) as demo: # don't change
14
+ vlai_template.create_header() # don't change
15
+
16
+ with gr.Row(equal_height=True, variant="panel"):
17
+ with gr.Column(scale=3):
18
+ upload_image = gr.Image(label="Upload image", type="pil")
19
+ prompt_input = gr.Textbox(label="Optional prompt", placeholder="e.g. Detect cats only")
20
+ task_choice = gr.Radio(["Auto", "Detection", "Segmentation"],
21
+ value="Auto", label="Task")
22
+ temp_slider = gr.Slider(minimum=0.1, maximum=1.5, step=0.1,
23
+ value=0.7, label="Temperature (sampling)")
24
+ submit_btn = gr.Button("Run 🔧", elem_classes="full-width-btn")
25
+
26
+ with gr.Column(scale=4):
27
+ output_text = gr.Markdown(label="Result")
28
+
29
+ submit_btn.click(
30
+ inference,
31
+ inputs=[upload_image, prompt_input, task_choice, temp_slider],
32
+ outputs=output_text,
33
+ )
34
+
35
+ vlai_template.create_footer() # don't change
36
+
37
+ if __name__ == "__main__":
38
+ demo.launch(allowed_paths=["static/aivn_logo.png", "static/vlai_logo.png", "static"]) # don't change
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio==5.38.0
src/__init__.py ADDED
File without changes
src/feat1/__init__.py ADDED
File without changes
src/feat1/placeholder.py ADDED
File without changes
src/feat2/__init__.py ADDED
File without changes
src/feat2/placeholder.py ADDED
File without changes
static/aivn_logo.png ADDED
static/vlai_logo.png ADDED
vlai_template.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, base64
2
+ import gradio as gr
3
+
4
+
5
+ # JUST CHANGE THESE VALUES IN THIS FILE
6
+ PROJECT_NAME = "PROJECT NAME"
7
+ AIO_YEAR = "2025"
8
+ AIO_MODULE = "2"
9
+ # END
10
+
11
+
12
+ def image_to_base64(image_path: str):
13
+ # Construct the absolute path to the image
14
+ current_dir = os.path.dirname(os.path.abspath(__file__))
15
+ full_image_path = os.path.join(current_dir, image_path)
16
+ with open(full_image_path, "rb") as f:
17
+ return base64.b64encode(f.read()).decode("utf-8")
18
+
19
+ def create_header():
20
+ with gr.Row():
21
+ with gr.Column(scale=2):
22
+ logo_base64 = image_to_base64("static/aivn_logo.png")
23
+ gr.HTML(
24
+ f"""<img src="data:image/png;base64,{logo_base64}"
25
+ alt="Logo"
26
+ style="height:120px;width:auto;margin:0 auto;margin-bottom:16px; display:block;">"""
27
+ )
28
+ with gr.Column(scale=2):
29
+ gr.HTML(f"""
30
+ <div style="display:flex;justify-content:flex-start;align-items:center;gap:30px;">
31
+ <div>
32
+ <h1 style="margin-bottom:0; color: #4f47e6; font-size: 2.5em; font-weight: bold;"> {PROJECT_NAME} </h1>
33
+ <h3 style="color: #888; font-style: italic"> AIO{AIO_YEAR}: Module {AIO_MODULE} </h3>
34
+ </div>
35
+ </div>
36
+ """)
37
+
38
+ def create_footer():
39
+ logo_base64_vlai = image_to_base64("static/vlai_logo.png")
40
+ footer_html = """
41
+ <style>
42
+ .sticky-footer{position:fixed;bottom:0px;left:0;width:100%;background:#F4EBD3;
43
+ padding:10px;box-shadow:0 -2px 10px rgba(0,0,0,0.1);z-index:1000;}
44
+ .content-wrap{padding-bottom:60px;}
45
+ </style>""" + f"""
46
+ <div class="sticky-footer">
47
+ <div style="text-align:center;font-size:18px; color: #888">
48
+ Created by
49
+ <a href="https://vlai.work" target="_blank" style="color:#465C88;text-decoration:none;font-weight:bold; display:inline-flex; align-items:center;">
50
+ <img src="data:image/png;base64,{logo_base64_vlai}" alt="Logo" style="height:20px; width:auto;"> VLAI
51
+ </a> from <a href="https://aivietnam.edu.vn/" target="_blank" style="color:#355724;text-decoration:none;font-weight:bold">AI VIET NAM</a>
52
+ </div>
53
+ </div>
54
+ """
55
+ return gr.HTML(footer_html)
56
+
57
+ custom_css = """
58
+ .gradio-container {
59
+ min-height:64vh;
60
+ background: linear-gradient(135deg, #F5EFE6 0%, #E8DFCA 50%, #AEBDCA 100%);
61
+ background-size: 400% 400%;
62
+ animation: gradientBG 10s ease infinite;
63
+ }
64
+ @keyframes gradientBG {
65
+ 0% {background-position: 0% 50%;}
66
+ 50% {background-position: 100% 50%;}
67
+ 100% {background-position: 0% 50%;}
68
+ }
69
+ .content-wrap {padding-bottom:8px;}
70
+ """