Update app-backup1.py
Browse files- app-backup1.py +245 -150
app-backup1.py
CHANGED
|
@@ -172,160 +172,255 @@ async def try_openai_api(openai_messages):
|
|
| 172 |
print(f"OpenAI API error: {str(e)}")
|
| 173 |
raise e
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
class Demo:
|
| 176 |
def __init__(self):
|
| 177 |
pass
|
| 178 |
-
|
| 179 |
async def generation_code(self, query: Optional[str], _setting: Dict[str, str], _history: Optional[History]):
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
yield [
|
| 219 |
-
code,
|
| 220 |
-
_history,
|
| 221 |
-
analysis,
|
| 222 |
-
gr.update(active_key="loading"),
|
| 223 |
-
gr.update(open=True)
|
| 224 |
-
]
|
| 225 |
-
await asyncio.sleep(0)
|
| 226 |
-
collected_content = code
|
| 227 |
-
|
| 228 |
-
except Exception as claude_error:
|
| 229 |
-
print(f"Falling back to OpenAI API due to Claude error: {str(claude_error)}")
|
| 230 |
-
|
| 231 |
-
async for content in try_openai_api(openai_messages):
|
| 232 |
-
code = content
|
| 233 |
-
analysis = analyze_code(code)
|
| 234 |
-
yield [
|
| 235 |
-
code,
|
| 236 |
-
_history,
|
| 237 |
-
analysis,
|
| 238 |
-
gr.update(active_key="loading"),
|
| 239 |
-
gr.update(open=True)
|
| 240 |
-
]
|
| 241 |
-
await asyncio.sleep(0)
|
| 242 |
-
collected_content = code
|
| 243 |
-
|
| 244 |
-
if collected_content:
|
| 245 |
-
_history = messages_to_history([
|
| 246 |
-
{'role': Role.SYSTEM, 'content': system_message}
|
| 247 |
-
] + claude_messages + [{
|
| 248 |
-
'role': Role.ASSISTANT,
|
| 249 |
-
'content': collected_content
|
| 250 |
-
}])
|
| 251 |
-
|
| 252 |
yield [
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
]
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
current_func = []
|
| 300 |
-
|
| 301 |
-
if functions:
|
| 302 |
-
analysis.append("## ๐ง ์ฃผ์ ํจ์")
|
| 303 |
-
for func in functions:
|
| 304 |
-
func_name = func.split('def ')[1].split('(')[0]
|
| 305 |
-
analysis.append(f"### `{func_name}`")
|
| 306 |
-
analysis.append(get_function_description(func))
|
| 307 |
-
analysis.append("")
|
| 308 |
-
|
| 309 |
-
# 3. UI ์ปดํฌ๋ํธ ๋ถ์
|
| 310 |
-
ui_components = []
|
| 311 |
-
for line in code.split('\n'):
|
| 312 |
-
if 'gr.' in line:
|
| 313 |
-
component = line.split('gr.')[1].split('(')[0]
|
| 314 |
-
if component not in ui_components:
|
| 315 |
-
ui_components.append(component)
|
| 316 |
-
|
| 317 |
-
if ui_components:
|
| 318 |
-
analysis.append("## ๐จ UI ์ปดํฌ๋ํธ")
|
| 319 |
-
for component in ui_components:
|
| 320 |
-
analysis.append(f"- **{component}**: {get_component_description(component)}")
|
| 321 |
-
analysis.append("")
|
| 322 |
-
|
| 323 |
-
# 4. ์คํ ๋ฐฉ๋ฒ
|
| 324 |
-
analysis.append("## โถ๏ธ ์คํ ๋ฐฉ๋ฒ")
|
| 325 |
-
analysis.append("1. '์คํํ๊ธฐ' ๋ฒํผ์ ํด๋ฆญํ์ฌ Hugging Face Space์ ๋ฐฐํฌ")
|
| 326 |
-
analysis.append("2. ์์ฑ๋ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ์ ํ๋ฆฌ์ผ์ด์
์คํ")
|
| 327 |
-
|
| 328 |
-
return "\n".join(analysis)
|
| 329 |
|
| 330 |
def clear_history(self):
|
| 331 |
return []
|
|
@@ -1092,8 +1187,8 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
| 1092 |
header = gr.HTML(f"""
|
| 1093 |
<div class="left_header">
|
| 1094 |
<img src="data:image/gif;base64,{get_image_base64('mouse.gif')}" width="360px" />
|
| 1095 |
-
<h1 style="font-size: 18px;">๊ณ ์์ด๋ ๋ฐ๋ก ์ฝ๋ฉํ๋ 'MOUSE-
|
| 1096 |
-
<h1 style="font-size: 10px;"
|
| 1097 |
</div>
|
| 1098 |
""")
|
| 1099 |
input = antd.InputTextarea(
|
|
|
|
| 172 |
print(f"OpenAI API error: {str(e)}")
|
| 173 |
raise e
|
| 174 |
|
| 175 |
+
|
| 176 |
+
def analyze_code(code: str) -> str:
|
| 177 |
+
"""์ฝ๋ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ HTML ํ์์ผ๋ก ๋ฐํ"""
|
| 178 |
+
analysis = []
|
| 179 |
+
|
| 180 |
+
# 0. ์ฝ๋ ๊ฐ์
|
| 181 |
+
analysis.append("<h2>๐ก ์ฝ๋ ๊ฐ์</h2>")
|
| 182 |
+
analysis.append("<p>์ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ ํน์ง์ ๊ฐ์ง๊ณ ์์ต๋๋ค:</p>")
|
| 183 |
+
analysis.append("<ul>")
|
| 184 |
+
if 'gr.Blocks' in code:
|
| 185 |
+
analysis.append("<li>Gradio Blocks๋ฅผ ์ฌ์ฉํ ๋ชจ๋ํ UI ๊ตฌ์ฑ</li>")
|
| 186 |
+
if 'theme=' in code:
|
| 187 |
+
analysis.append("<li>์ปค์คํ
ํ
๋ง ์ ์ฉ์ผ๋ก ์๊ฐ์ ์ผ๊ด์ฑ ์ ์ง</li>")
|
| 188 |
+
if 'with gr.Row' in code or 'with gr.Column' in code:
|
| 189 |
+
analysis.append("<li>Row/Column ๋ ์ด์์์ผ๋ก ๋ฐ์ํ ๋์์ธ ๊ตฌํ</li>")
|
| 190 |
+
analysis.append("</ul>")
|
| 191 |
+
|
| 192 |
+
# 1. ์ฌ์ฉ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ถ์
|
| 193 |
+
imports = []
|
| 194 |
+
required_packages = set()
|
| 195 |
+
for line in code.split('\n'):
|
| 196 |
+
if line.startswith('import ') or line.startswith('from '):
|
| 197 |
+
imports.append(line.strip())
|
| 198 |
+
# ํจํค์ง ์ด๋ฆ ์ถ์ถ
|
| 199 |
+
if line.startswith('import '):
|
| 200 |
+
package = line.split('import ')[1].split()[0].split('.')[0]
|
| 201 |
+
else:
|
| 202 |
+
package = line.split('from ')[1].split()[0].split('.')[0]
|
| 203 |
+
required_packages.add(package)
|
| 204 |
+
|
| 205 |
+
if imports:
|
| 206 |
+
analysis.append("<h2>๐ ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ</h2>")
|
| 207 |
+
analysis.append("<ul>")
|
| 208 |
+
for imp in imports:
|
| 209 |
+
analysis.append(f"<li><code>{imp}</code></li>")
|
| 210 |
+
analysis.append("</ul>")
|
| 211 |
+
|
| 212 |
+
# requirements.txt ์ค๋ช
์ถ๊ฐ
|
| 213 |
+
analysis.append("<h3>๐ Requirements.txt</h3>")
|
| 214 |
+
analysis.append("<p>์ด ์ฑ์ ์คํํ๊ธฐ ์ํด ํ์ํ ํจํค์ง๋ค์
๋๋ค:</p>")
|
| 215 |
+
analysis.append("<pre>")
|
| 216 |
+
for pkg in sorted(required_packages):
|
| 217 |
+
if pkg == 'gradio':
|
| 218 |
+
analysis.append("gradio==5.5.0")
|
| 219 |
+
else:
|
| 220 |
+
analysis.append(pkg)
|
| 221 |
+
analysis.append("</pre>")
|
| 222 |
+
|
| 223 |
+
# 2. ํจ์ ๋ถ์
|
| 224 |
+
functions = []
|
| 225 |
+
current_func = []
|
| 226 |
+
in_function = False
|
| 227 |
+
|
| 228 |
+
for line in code.split('\n'):
|
| 229 |
+
if line.strip().startswith('def '):
|
| 230 |
+
if current_func:
|
| 231 |
+
functions.append('\n'.join(current_func))
|
| 232 |
+
current_func = []
|
| 233 |
+
in_function = True
|
| 234 |
+
if in_function:
|
| 235 |
+
current_func.append(line)
|
| 236 |
+
if in_function and not line.strip():
|
| 237 |
+
in_function = False
|
| 238 |
+
if current_func:
|
| 239 |
+
functions.append('\n'.join(current_func))
|
| 240 |
+
current_func = []
|
| 241 |
+
|
| 242 |
+
if functions:
|
| 243 |
+
analysis.append("<h2>๐ง ์ฃผ์ ํจ์ ์ค๋ช
</h2>")
|
| 244 |
+
for func in functions:
|
| 245 |
+
func_name = func.split('def ')[1].split('(')[0]
|
| 246 |
+
analysis.append(f"<h3><code>{func_name}</code></h3>")
|
| 247 |
+
analysis.append(f"<p>{get_function_description(func)}</p>")
|
| 248 |
+
# ํจ์ ํ๋ผ๋ฏธํฐ ๋ถ์
|
| 249 |
+
params = func.split('(')[1].split(')')[0]
|
| 250 |
+
if params.strip():
|
| 251 |
+
analysis.append("<p>ํ๋ผ๋ฏธํฐ:</p><ul>")
|
| 252 |
+
for param in params.split(','):
|
| 253 |
+
param = param.strip()
|
| 254 |
+
if param and param != 'self':
|
| 255 |
+
analysis.append(f"<li><code>{param}</code></li>")
|
| 256 |
+
analysis.append("</ul>")
|
| 257 |
+
|
| 258 |
+
# 3. UI ์ปดํฌ๋ํธ ๋ถ์
|
| 259 |
+
ui_components = []
|
| 260 |
+
for line in code.split('\n'):
|
| 261 |
+
if 'gr.' in line:
|
| 262 |
+
component = line.split('gr.')[1].split('(')[0]
|
| 263 |
+
if component not in ui_components:
|
| 264 |
+
ui_components.append(component)
|
| 265 |
+
|
| 266 |
+
if ui_components:
|
| 267 |
+
analysis.append("<h2>๐จ UI ๊ตฌ์ฑ์์</h2>")
|
| 268 |
+
analysis.append("<p>์ด ์ฑ์ ๋ค์๊ณผ ๊ฐ์ Gradio ์ปดํฌ๋ํธ๋ค๋ก ๊ตฌ์ฑ๋์ด ์์ต๋๋ค:</p>")
|
| 269 |
+
analysis.append("<ul>")
|
| 270 |
+
for component in ui_components:
|
| 271 |
+
analysis.append(f"<li><strong>{component}</strong>: {get_component_description(component)}</li>")
|
| 272 |
+
analysis.append("</ul>")
|
| 273 |
+
|
| 274 |
+
# 4. ํน์ง ๋ฐ ๊ธฐ๋ฅ
|
| 275 |
+
analysis.append("<h2>โจ ์ฃผ์ ํน์ง</h2>")
|
| 276 |
+
analysis.append("<ul>")
|
| 277 |
+
if 'theme=' in code:
|
| 278 |
+
analysis.append("<li>์ปค์คํ
ํ
๋ง ์ ์ฉ์ผ๋ก ์ผ๊ด๋ ๋์์ธ</li>")
|
| 279 |
+
if 'with gr.Row' in code:
|
| 280 |
+
analysis.append("<li>๋ฐ์ํ ๋ ์ด์์์ผ๋ก ๋ค์ํ ํ๋ฉด ํฌ๊ธฐ ์ง์</li>")
|
| 281 |
+
if 'gr.State' in code:
|
| 282 |
+
analysis.append("<li>์ํ ๊ด๋ฆฌ๋ฅผ ํตํ ๋ฐ์ดํฐ ์ ์ง</li>")
|
| 283 |
+
if '.click(' in code:
|
| 284 |
+
analysis.append("<li>์ด๋ฒคํธ ํธ๋ค๋ง์ ํตํ ๋์ ์ํธ์์ฉ</li>")
|
| 285 |
+
analysis.append("</ul>")
|
| 286 |
+
|
| 287 |
+
# 5. ์คํ ๋ฐฉ๋ฒ
|
| 288 |
+
analysis.append("<h2>โถ๏ธ ์คํ ๋ฐฉ๋ฒ</h2>")
|
| 289 |
+
analysis.append("<ol>")
|
| 290 |
+
analysis.append("<li>'์คํํ๊ธฐ' ๋ฒํผ์ ํด๋ฆญํ์ฌ Hugging Face Space์ ๋ฐฐํฌ</li>")
|
| 291 |
+
analysis.append("<li>์์ฑ๋ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ์ ํ๋ฆฌ์ผ์ด์
์คํ</li>")
|
| 292 |
+
analysis.append("<li>ํ์ํ ์
๋ ฅ๊ฐ์ ์ ๊ณตํ๊ณ ์ํธ์์ฉ ์์</li>")
|
| 293 |
+
analysis.append("</ol>")
|
| 294 |
+
|
| 295 |
+
return "\n".join(analysis)
|
| 296 |
+
|
| 297 |
+
def get_function_description(func: str) -> str:
|
| 298 |
+
"""ํจ์์ ๋ชฉ์ ์ ์ค๋ช
ํ๋ ๋ฌธ์์ด ๋ฐํ"""
|
| 299 |
+
if 'get_multiplication_table' in func:
|
| 300 |
+
return "์
๋ ฅ๋ฐ์ ์ซ์์ ๊ตฌ๊ตฌ๋จ์ ๊ณ์ฐํ์ฌ ๋ฌธ์์ด๋ก ๋ฐํ"
|
| 301 |
+
elif 'get_all_tables' in func:
|
| 302 |
+
return "2๋จ๋ถํฐ 9๋จ๊น์ง ์ ์ฒด ๊ตฌ๊ตฌ๋จ์ ์์ฑํ์ฌ ๋ฐํ"
|
| 303 |
+
# ๋ค๋ฅธ ํจ์๋ค์ ๋ํ ์ค๋ช
์ถ๊ฐ
|
| 304 |
+
return "ํจ์์ ๊ธฐ๋ฅ ์ค๋ช
"
|
| 305 |
+
|
| 306 |
+
def get_component_description(component: str) -> str:
|
| 307 |
+
"""UI ์ปดํฌ๋ํธ์ ๋ํ ์ค๋ช
๋ฐํ"""
|
| 308 |
+
descriptions = {
|
| 309 |
+
'Number': '์ซ์ ์
๋ ฅ ํ๋',
|
| 310 |
+
'Button': 'ํด๋ฆญ ๊ฐ๋ฅํ ๋ฒํผ',
|
| 311 |
+
'Textbox': 'ํ
์คํธ ์ถ๋ ฅ ์์ญ',
|
| 312 |
+
'Markdown': '๋งํฌ๋ค์ด ํ์์ ํ
์คํธ ํ์',
|
| 313 |
+
'Row': '์ํ ๋ฐฉํฅ ๋ ์ด์์',
|
| 314 |
+
'Column': '์์ง ๋ฐฉํฅ ๋ ์ด์์',
|
| 315 |
+
'Blocks': '์ ์ฒด UI ์ปจํ
์ด๋',
|
| 316 |
+
'Image': '์ด๋ฏธ์ง ํ์ ์ปดํฌ๋ํธ',
|
| 317 |
+
'File': 'ํ์ผ ์
๋ก๋ ์ปดํฌ๋ํธ',
|
| 318 |
+
'Slider': '์ฌ๋ผ์ด๋ ์
๋ ฅ ์ปดํฌ๋ํธ',
|
| 319 |
+
'Dropdown': '๋๋กญ๋ค์ด ์ ํ ์ปดํฌ๋ํธ',
|
| 320 |
+
'Radio': '๋ผ๋์ค ๋ฒํผ ๊ทธ๋ฃน',
|
| 321 |
+
'Checkbox': '์ฒดํฌ๋ฐ์ค ์ปดํฌ๋ํธ',
|
| 322 |
+
'Audio': '์ค๋์ค ์ฌ์/๋
น์ ์ปดํฌ๋ํธ',
|
| 323 |
+
'Video': '๋น๋์ค ์ฌ์ ์ปดํฌ๋ํธ',
|
| 324 |
+
'HTML': 'HTML ์ฝํ
์ธ ํ์',
|
| 325 |
+
'JSON': 'JSON ๋ฐ์ดํฐ ํ์',
|
| 326 |
+
'DataFrame': '๋ฐ์ดํฐํ๋ ์ ํ์',
|
| 327 |
+
'Plot': '๊ทธ๋ํ/์ฐจํธ ํ์',
|
| 328 |
+
'Label': '๋ ์ด๋ธ ํ
์คํธ ํ์'
|
| 329 |
+
}
|
| 330 |
+
return descriptions.get(component, '์ปดํฌ๋ํธ ์ค๋ช
')
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
|
| 334 |
class Demo:
|
| 335 |
def __init__(self):
|
| 336 |
pass
|
| 337 |
+
|
| 338 |
async def generation_code(self, query: Optional[str], _setting: Dict[str, str], _history: Optional[History]):
|
| 339 |
+
if not query or query.strip() == '':
|
| 340 |
+
query = random.choice(DEMO_LIST)['description']
|
| 341 |
+
|
| 342 |
+
if _history is None:
|
| 343 |
+
_history = []
|
| 344 |
+
|
| 345 |
+
messages = history_to_messages(_history, _setting['system'])
|
| 346 |
+
system_message = messages[0]['content']
|
| 347 |
+
|
| 348 |
+
claude_messages = [
|
| 349 |
+
{"role": msg["role"] if msg["role"] != "system" else "user", "content": msg["content"]}
|
| 350 |
+
for msg in messages[1:] + [{'role': Role.USER, 'content': query}]
|
| 351 |
+
if msg["content"].strip() != ''
|
| 352 |
+
]
|
| 353 |
+
|
| 354 |
+
openai_messages = [{"role": "system", "content": system_message}]
|
| 355 |
+
for msg in messages[1:]:
|
| 356 |
+
openai_messages.append({
|
| 357 |
+
"role": msg["role"],
|
| 358 |
+
"content": msg["content"]
|
| 359 |
+
})
|
| 360 |
+
openai_messages.append({"role": "user", "content": query})
|
| 361 |
+
|
| 362 |
+
try:
|
| 363 |
+
yield [
|
| 364 |
+
"Generating code...",
|
| 365 |
+
_history,
|
| 366 |
+
None,
|
| 367 |
+
gr.update(active_key="loading"),
|
| 368 |
+
gr.update(open=True)
|
| 369 |
+
]
|
| 370 |
+
await asyncio.sleep(0)
|
| 371 |
+
|
| 372 |
+
collected_content = None
|
| 373 |
+
try:
|
| 374 |
+
async for content in try_claude_api(system_message, claude_messages):
|
| 375 |
+
code = content
|
| 376 |
+
analysis = analyze_code(code)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
yield [
|
| 378 |
+
code,
|
| 379 |
+
_history,
|
| 380 |
+
analysis, # ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ HTML๋ก ์ ๋ฌ
|
| 381 |
+
gr.update(active_key="loading"),
|
| 382 |
+
gr.update(open=True)
|
| 383 |
]
|
| 384 |
+
await asyncio.sleep(0)
|
| 385 |
+
collected_content = code
|
| 386 |
+
|
| 387 |
+
except Exception as claude_error:
|
| 388 |
+
print(f"Falling back to OpenAI API due to Claude error: {str(claude_error)}")
|
| 389 |
+
|
| 390 |
+
async for content in try_openai_api(openai_messages):
|
| 391 |
+
code = content
|
| 392 |
+
analysis = analyze_code(code)
|
| 393 |
+
yield [
|
| 394 |
+
code,
|
| 395 |
+
_history,
|
| 396 |
+
analysis, # ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ HTML๋ก ์ ๋ฌ
|
| 397 |
+
gr.update(active_key="loading"),
|
| 398 |
+
gr.update(open=True)
|
| 399 |
+
]
|
| 400 |
+
await asyncio.sleep(0)
|
| 401 |
+
collected_content = code
|
| 402 |
+
|
| 403 |
+
if collected_content:
|
| 404 |
+
_history = messages_to_history([
|
| 405 |
+
{'role': Role.SYSTEM, 'content': system_message}
|
| 406 |
+
] + claude_messages + [{
|
| 407 |
+
'role': Role.ASSISTANT,
|
| 408 |
+
'content': collected_content
|
| 409 |
+
}])
|
| 410 |
+
|
| 411 |
+
yield [
|
| 412 |
+
collected_content,
|
| 413 |
+
_history,
|
| 414 |
+
analyze_code(collected_content), # ์ต์ข
๋ถ์ ๊ฒฐ๊ณผ๋ฅผ HTML๋ก ์ ๋ฌ
|
| 415 |
+
gr.update(active_key="render"),
|
| 416 |
+
gr.update(open=True)
|
| 417 |
+
]
|
| 418 |
+
else:
|
| 419 |
+
raise ValueError("No content was generated from either API")
|
| 420 |
+
|
| 421 |
+
except Exception as e:
|
| 422 |
+
print(f"Error details: {str(e)}")
|
| 423 |
+
raise ValueError(f'Error calling APIs: {str(e)}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
|
| 425 |
def clear_history(self):
|
| 426 |
return []
|
|
|
|
| 1187 |
header = gr.HTML(f"""
|
| 1188 |
<div class="left_header">
|
| 1189 |
<img src="data:image/gif;base64,{get_image_base64('mouse.gif')}" width="360px" />
|
| 1190 |
+
<h1 style="font-size: 18px;">๊ณ ์์ด๋ ๋ฐ๋ก ์ฝ๋ฉํ๋ 'MOUSE-II'</h2>
|
| 1191 |
+
<h1 style="font-size: 10px;">ํ
ํ๋ฆฟ์ ํ๋กฌํํธ ๋ด์ฉ์ ๋ณต์ฌํด ํ๋กฌํํธ์ ์
๋ ฅ 'Send'๋ฒํผ ํด๋ฆญ -> '์คํํ๊ธฐ' ๋ฒํผ ํด๋ฆญํ์ฌ ์ฝ๋ ์คํ. ๋ฌธ์: [email protected] </h2>
|
| 1192 |
</div>
|
| 1193 |
""")
|
| 1194 |
input = antd.InputTextarea(
|