seawolf2357 commited on
Commit
16cc2de
Β·
verified Β·
1 Parent(s): c6aea04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -32
app.py CHANGED
@@ -4,8 +4,7 @@ from http import HTTPStatus
4
  from typing import Dict, List, Optional, Tuple
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,11 +12,6 @@ import modelscope_studio.components.legacy as legacy
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):
23
  with open(image_path, "rb") as image_file:
@@ -68,28 +62,9 @@ def send_to_sandbox(code):
68
  data_uri = f"data:text/html;charset=utf-8;base64,{encoded_html}"
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([])
@@ -102,12 +77,10 @@ with gr.Blocks(css_paths="app.css") as demo:
102
  with antd.Row(gutter=[32, 12]) as layout:
103
  with antd.Col(span=24, md=8):
104
  with antd.Flex(vertical=True, gap="middle", wrap=True):
105
- # μˆ˜μ •λœ header λΆ€λΆ„
106
  header = gr.HTML(f"""
107
  <div class="left_header">
108
  <img src="data:image/gif;base64,{get_image_base64('mouse.gif')}" width="360px" />
109
  <h1 style="font-size: 20px;">AI μ½”λ”© μ½”νŒŒμΌλŸΏ: MOUSE(WEB)</h2>
110
-
111
  </div>
112
  """)
113
  input = antd.InputTextarea(
@@ -115,8 +88,6 @@ with gr.Blocks(css_paths="app.css") as demo:
115
  allow_clear=True,
116
  placeholder="Please enter what kind of application you want"
117
  )
118
-
119
-
120
 
121
  btn = antd.Button("send", type="primary", size="large")
122
  clear_btn = antd.Button("clear history", type="default", size="large")
@@ -126,7 +97,7 @@ with gr.Blocks(css_paths="app.css") as demo:
126
  with ms.Each(DEMO_LIST):
127
  with antd.Card(hoverable=True, as_item="card") as demoCard:
128
  antd.CardMeta()
129
- demoCard.click(demo_card_click, outputs=[input])
130
 
131
  antd.Divider("setting")
132
 
 
4
  from typing import Dict, List, Optional, Tuple
5
  import base64
6
  import anthropic
7
+ from functools import partial
 
8
 
9
  import gradio as gr
10
  import modelscope_studio.components.base as ms
 
12
  import modelscope_studio.components.antd as antd
13
  from config import DEMO_LIST, SystemPrompt
14
 
 
 
 
 
 
15
  # 파일 μƒλ‹¨μ˜ import λ¬Έ μ•„λž˜μ— μΆ”κ°€
16
  def get_image_base64(image_path):
17
  with open(image_path, "rb") as image_file:
 
62
  data_uri = f"data:text/html;charset=utf-8;base64,{encoded_html}"
63
  return f"<iframe src=\"{data_uri}\" width=\"100%\" height=\"920px\"></iframe>"
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  def demo_card_click(e: gr.EventData):
66
  index = e._data['component']['index']
67
+ return DEMO_LIST[index]['description']
68
 
69
  with gr.Blocks(css_paths="app.css") as demo:
70
  history = gr.State([])
 
77
  with antd.Row(gutter=[32, 12]) as layout:
78
  with antd.Col(span=24, md=8):
79
  with antd.Flex(vertical=True, gap="middle", wrap=True):
 
80
  header = gr.HTML(f"""
81
  <div class="left_header">
82
  <img src="data:image/gif;base64,{get_image_base64('mouse.gif')}" width="360px" />
83
  <h1 style="font-size: 20px;">AI μ½”λ”© μ½”νŒŒμΌλŸΏ: MOUSE(WEB)</h2>
 
84
  </div>
85
  """)
86
  input = antd.InputTextarea(
 
88
  allow_clear=True,
89
  placeholder="Please enter what kind of application you want"
90
  )
 
 
91
 
92
  btn = antd.Button("send", type="primary", size="large")
93
  clear_btn = antd.Button("clear history", type="default", size="large")
 
97
  with ms.Each(DEMO_LIST):
98
  with antd.Card(hoverable=True, as_item="card") as demoCard:
99
  antd.CardMeta()
100
+ demoCard.click(demo_card_click, outputs=[input], api_name="demo_click", cache=True)
101
 
102
  antd.Divider("setting")
103