Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ from typing import Dict, List, Optional, Tuple
|
|
5 |
import base64
|
6 |
import anthropic
|
7 |
from functools import partial, lru_cache
|
|
|
8 |
|
9 |
import gradio as gr
|
10 |
import modelscope_studio.components.base as ms
|
@@ -12,6 +13,10 @@ import modelscope_studio.components.legacy as legacy
|
|
12 |
import modelscope_studio.components.antd as antd
|
13 |
from config import DEMO_LIST, SystemPrompt
|
14 |
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# νμΌ μλ¨μ import λ¬Έ μλμ μΆκ°
|
17 |
def get_image_base64(image_path):
|
@@ -64,15 +69,27 @@ def send_to_sandbox(code):
|
|
64 |
return f"<iframe src=\"{data_uri}\" width=\"100%\" height=\"920px\"></iframe>"
|
65 |
|
66 |
|
67 |
-
#
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
def demo_card_click(e: gr.EventData):
|
73 |
index = e._data['component']['index']
|
74 |
-
return
|
75 |
-
|
76 |
|
77 |
with gr.Blocks(css_paths="app.css") as demo:
|
78 |
history = gr.State([])
|
|
|
5 |
import base64
|
6 |
import anthropic
|
7 |
from functools import partial, lru_cache
|
8 |
+
import json
|
9 |
|
10 |
import gradio as gr
|
11 |
import modelscope_studio.components.base as ms
|
|
|
13 |
import modelscope_studio.components.antd as antd
|
14 |
from config import DEMO_LIST, SystemPrompt
|
15 |
|
16 |
+
# μΊμ μ μ₯μ
|
17 |
+
DEMO_CACHE = {}
|
18 |
+
|
19 |
+
|
20 |
|
21 |
# νμΌ μλ¨μ import λ¬Έ μλμ μΆκ°
|
22 |
def get_image_base64(image_path):
|
|
|
69 |
return f"<iframe src=\"{data_uri}\" width=\"100%\" height=\"920px\"></iframe>"
|
70 |
|
71 |
|
72 |
+
# μΊμλ λ°λͺ¨ μ€λͺ
μ κ°μ Έμ€λ ν¨μ
|
73 |
+
def get_cached_demo_description(index: int) -> str:
|
74 |
+
if index not in DEMO_CACHE:
|
75 |
+
DEMO_CACHE[index] = DEMO_LIST[index]['description']
|
76 |
+
# μΊμ νμΌμ μ μ₯
|
77 |
+
with open('demo_cache.json', 'w', encoding='utf-8') as f:
|
78 |
+
json.dump(DEMO_CACHE, f, ensure_ascii=False, indent=2)
|
79 |
+
return DEMO_CACHE[index]
|
80 |
+
|
81 |
+
# μμν λ μΊμ λ‘λ
|
82 |
+
try:
|
83 |
+
with open('demo_cache.json', 'r', encoding='utf-8') as f:
|
84 |
+
DEMO_CACHE = json.load(f)
|
85 |
+
except FileNotFoundError:
|
86 |
+
# μ²μ μ€νμ μΊμ μ΄κΈ°ν
|
87 |
+
for i in range(len(DEMO_LIST)):
|
88 |
+
get_cached_demo_description(i)
|
89 |
|
90 |
def demo_card_click(e: gr.EventData):
|
91 |
index = e._data['component']['index']
|
92 |
+
return get_cached_demo_description(index)
|
|
|
93 |
|
94 |
with gr.Blocks(css_paths="app.css") as demo:
|
95 |
history = gr.State([])
|