ai: Allowed ext files for documents scanning.
Browse files
app.py
CHANGED
@@ -33,7 +33,7 @@ from PIL import Image
|
|
33 |
LINUX_SERVER_HOSTS = [host for host in json.loads(os.getenv("LINUX_SERVER_HOST", "[]")) if host]
|
34 |
LINUX_SERVER_PROVIDER_KEYS = [key for key in json.loads(os.getenv("LINUX_SERVER_PROVIDER_KEY", "[]")) if key]
|
35 |
|
36 |
-
AI_TYPES = {f"AI_TYPE_{i}": os.getenv(f"AI_TYPE_{i}") for i in range(1,
|
37 |
RESPONSES = {f"RESPONSE_{i}": os.getenv(f"RESPONSE_{i}") for i in range(1, 10)}
|
38 |
|
39 |
MODEL_MAPPING = json.loads(os.getenv("MODEL_MAPPING", "{}"))
|
@@ -43,6 +43,8 @@ DEFAULT_CONFIG = json.loads(os.getenv("DEFAULT_CONFIG", "{}"))
|
|
43 |
|
44 |
META_TAGS = os.getenv("META_TAGS")
|
45 |
|
|
|
|
|
46 |
stop_event = threading.Event()
|
47 |
session = requests.Session()
|
48 |
|
@@ -206,7 +208,14 @@ def stop_response():
|
|
206 |
def change_model(new_model_display):
|
207 |
return [], new_model_display
|
208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
def check_send_button_enabled(msg, file):
|
|
|
210 |
return gr.update(interactive=bool(msg.strip()) or bool(file))
|
211 |
|
212 |
with gr.Blocks(fill_height=True, fill_width=True, title=AI_TYPES["AI_TYPE_4"], head=META_TAGS) as demo:
|
@@ -215,12 +224,12 @@ with gr.Blocks(fill_height=True, fill_width=True, title=AI_TYPES["AI_TYPE_4"], h
|
|
215 |
|
216 |
chatbot = gr.Chatbot(label=AI_TYPES["AI_TYPE_1"], show_copy_button=True, show_share_button=False, scale=1, elem_id=AI_TYPES["AI_TYPE_2"])
|
217 |
model_dropdown = gr.Dropdown(label=AI_TYPES["AI_TYPE_3"], show_label=False, choices=MODEL_CHOICES, value=MODEL_CHOICES[0], interactive=True)
|
218 |
-
msg = gr.Textbox(label=RESPONSES["RESPONSE_4"], show_label=False, placeholder=RESPONSES["RESPONSE_5"])
|
219 |
send_btn = gr.Button(RESPONSES["RESPONSE_6"], visible=True, interactive=False)
|
220 |
stop_btn = gr.Button(RESPONSES["RESPONSE_7"], variant=RESPONSES["RESPONSE_9"], visible=False)
|
221 |
|
222 |
-
with gr.Accordion("
|
223 |
-
file_upload = gr.File(label=AI_TYPES["AI_TYPE_5"],
|
224 |
|
225 |
model_dropdown.change(fn=change_model, inputs=[model_dropdown], outputs=[user_history, selected_model])
|
226 |
send_btn.click(respond, inputs=[msg, file_upload, user_history, selected_model], outputs=[chatbot, msg, send_btn, stop_btn])
|
|
|
33 |
LINUX_SERVER_HOSTS = [host for host in json.loads(os.getenv("LINUX_SERVER_HOST", "[]")) if host]
|
34 |
LINUX_SERVER_PROVIDER_KEYS = [key for key in json.loads(os.getenv("LINUX_SERVER_PROVIDER_KEY", "[]")) if key]
|
35 |
|
36 |
+
AI_TYPES = {f"AI_TYPE_{i}": os.getenv(f"AI_TYPE_{i}") for i in range(1, 7)}
|
37 |
RESPONSES = {f"RESPONSE_{i}": os.getenv(f"RESPONSE_{i}") for i in range(1, 10)}
|
38 |
|
39 |
MODEL_MAPPING = json.loads(os.getenv("MODEL_MAPPING", "{}"))
|
|
|
43 |
|
44 |
META_TAGS = os.getenv("META_TAGS")
|
45 |
|
46 |
+
ALLOWED_EXTENSIONS = json.loads(os.getenv("ALLOWED_EXTENSIONS"))
|
47 |
+
|
48 |
stop_event = threading.Event()
|
49 |
session = requests.Session()
|
50 |
|
|
|
208 |
def change_model(new_model_display):
|
209 |
return [], new_model_display
|
210 |
|
211 |
+
def file_type_validation(file):
|
212 |
+
if file:
|
213 |
+
ext = Path(file.name).suffix.lower()
|
214 |
+
return ext in ALLOWED_EXTENSIONS
|
215 |
+
return False
|
216 |
+
|
217 |
def check_send_button_enabled(msg, file):
|
218 |
+
is_file_valid = file_type_validation(file)
|
219 |
return gr.update(interactive=bool(msg.strip()) or bool(file))
|
220 |
|
221 |
with gr.Blocks(fill_height=True, fill_width=True, title=AI_TYPES["AI_TYPE_4"], head=META_TAGS) as demo:
|
|
|
224 |
|
225 |
chatbot = gr.Chatbot(label=AI_TYPES["AI_TYPE_1"], show_copy_button=True, show_share_button=False, scale=1, elem_id=AI_TYPES["AI_TYPE_2"])
|
226 |
model_dropdown = gr.Dropdown(label=AI_TYPES["AI_TYPE_3"], show_label=False, choices=MODEL_CHOICES, value=MODEL_CHOICES[0], interactive=True)
|
227 |
+
msg = gr.Textbox(label=RESPONSES["RESPONSE_4"], show_label=False, placeholder=RESPONSES["RESPONSE_5"], interactive=True)
|
228 |
send_btn = gr.Button(RESPONSES["RESPONSE_6"], visible=True, interactive=False)
|
229 |
stop_btn = gr.Button(RESPONSES["RESPONSE_7"], variant=RESPONSES["RESPONSE_9"], visible=False)
|
230 |
|
231 |
+
with gr.Accordion(AI_TYPES["AI_TYPE_6"], open=False):
|
232 |
+
file_upload = gr.File(label=AI_TYPES["AI_TYPE_5"], file_count="single", type="filepath", file_types=ALLOWED_EXTENSIONS)
|
233 |
|
234 |
model_dropdown.change(fn=change_model, inputs=[model_dropdown], outputs=[user_history, selected_model])
|
235 |
send_btn.click(respond, inputs=[msg, file_upload, user_history, selected_model], outputs=[chatbot, msg, send_btn, stop_btn])
|