Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import base64
|
|
7 |
import json
|
8 |
import os
|
9 |
from PIL import Image
|
|
|
10 |
from io import BytesIO
|
11 |
|
12 |
invoke_url = "https://ai.api.nvidia.com/v1/gr/meta/llama-3.2-90b-vision-instruct/chat/completions"
|
@@ -67,6 +68,7 @@ def process_image(image_path, api_key, question):
|
|
67 |
yield full_response
|
68 |
except json.JSONDecodeError:
|
69 |
print(f"Failed to parse JSON: {json_str}")
|
|
|
70 |
return full_response
|
71 |
elif response.status_code == 402:
|
72 |
return "錯誤:API 帳號積分已過期。請至 NVIDIA 官網檢查您的帳號狀態。"
|
@@ -109,12 +111,6 @@ custom_css = """
|
|
109 |
padding: 15px !important;
|
110 |
border-radius: 10px !important;
|
111 |
}
|
112 |
-
.input-background textarea {
|
113 |
-
font-size: 18px !important;
|
114 |
-
background-color: #ffffff;
|
115 |
-
border: 1px solid #f0f8ff;
|
116 |
-
border-radius: 8px;
|
117 |
-
}
|
118 |
.gr-box {
|
119 |
border-radius: 10px !important;
|
120 |
border: 2px solid #ff4081 !important;
|
@@ -129,12 +125,6 @@ custom_css = """
|
|
129 |
padding: 15px !important;
|
130 |
border-radius: 10px !important;
|
131 |
}
|
132 |
-
.output-background textarea {
|
133 |
-
font-size: 18px !important;
|
134 |
-
background-color: #ffffff;
|
135 |
-
border: 1px solid #f0f8ff;
|
136 |
-
border-radius: 8px;
|
137 |
-
}
|
138 |
.image-background {
|
139 |
border-radius: 10px !important;
|
140 |
border: 2px solid #B7E0FF !important;
|
@@ -158,7 +148,7 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css=custom_css) as demo:
|
|
158 |
with gr.Row():
|
159 |
question_input = gr.Textbox(label="請輸入您的問題", placeholder="例如:What is in this image?", scale=2, elem_classes="input-background")
|
160 |
api_key_input = gr.Textbox(type="password", label="請輸入您的 API Key", placeholder="API authentication key for large language models", scale=1, elem_classes="api-background")
|
161 |
-
output = gr.Textbox(label="Vision Model 回覆",
|
162 |
with gr.Row():
|
163 |
submit_button = gr.Button("傳送", variant="primary", scale=2, elem_classes="gen-button")
|
164 |
clear_button = gr.Button("清除", variant="secondary", scale=1, elem_classes="clear-button")
|
|
|
7 |
import json
|
8 |
import os
|
9 |
from PIL import Image
|
10 |
+
from zhconv_rs import zhconv
|
11 |
from io import BytesIO
|
12 |
|
13 |
invoke_url = "https://ai.api.nvidia.com/v1/gr/meta/llama-3.2-90b-vision-instruct/chat/completions"
|
|
|
68 |
yield full_response
|
69 |
except json.JSONDecodeError:
|
70 |
print(f"Failed to parse JSON: {json_str}")
|
71 |
+
full_response = zhconv(full_response, "zh-tw")
|
72 |
return full_response
|
73 |
elif response.status_code == 402:
|
74 |
return "錯誤:API 帳號積分已過期。請至 NVIDIA 官網檢查您的帳號狀態。"
|
|
|
111 |
padding: 15px !important;
|
112 |
border-radius: 10px !important;
|
113 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
.gr-box {
|
115 |
border-radius: 10px !important;
|
116 |
border: 2px solid #ff4081 !important;
|
|
|
125 |
padding: 15px !important;
|
126 |
border-radius: 10px !important;
|
127 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
.image-background {
|
129 |
border-radius: 10px !important;
|
130 |
border: 2px solid #B7E0FF !important;
|
|
|
148 |
with gr.Row():
|
149 |
question_input = gr.Textbox(label="請輸入您的問題", placeholder="例如:What is in this image?", scale=2, elem_classes="input-background")
|
150 |
api_key_input = gr.Textbox(type="password", label="請輸入您的 API Key", placeholder="API authentication key for large language models", scale=1, elem_classes="api-background")
|
151 |
+
output = gr.Textbox(label="Vision Model 回覆", elem_classes="output-background", max_lines=20)
|
152 |
with gr.Row():
|
153 |
submit_button = gr.Button("傳送", variant="primary", scale=2, elem_classes="gen-button")
|
154 |
clear_button = gr.Button("清除", variant="secondary", scale=1, elem_classes="clear-button")
|