openfree commited on
Commit
59be132
·
verified ·
1 Parent(s): 3cc45f6

Rename app-backup.py to app-오리지날-backup.py

Browse files
app-backup.py → app-오리지날-backup.py RENAMED
@@ -1,3 +1,6 @@
 
 
 
1
  #!/usr/bin/env python3
2
 
3
  import os
@@ -233,7 +236,7 @@ def analyze_image_for_robot(
233
  task_type: str = "general",
234
  use_web_search: bool = False,
235
  enable_thinking: bool = False, # 기본값 False로 변경
236
- max_new_tokens: int = 250 # 기본값 250으로 변경
237
  ) -> str:
238
  """로봇 작업을 위한 이미지 분석"""
239
  global model, processor
@@ -249,23 +252,27 @@ def analyze_image_for_robot(
249
 
250
  # 태스크별 시스템 프롬프트 구성 (더 간결하게)
251
  system_prompts = {
252
- "general": "당신은 로봇 시각 시스템입니다. 핵심 내용만 간결하게 설명하세요.",
253
  "planning": """당신은 로봇 작업 계획 AI입니다.
254
- 주요 단계만 간결하게 작성하세요.
255
- 형식: Step_1: xxx
 
 
 
 
256
  Step_2: xxx
257
  Step_n: xxx""",
258
- "grounding": "당신은 객체 위치 시스템입니다. 객체 위치를 [x1, y1, x2, y2]로 반환하세요.",
259
- "affordance": "당신은 파지점 분석 AI입니다. 파지 영역을 [x1, y1, x2, y2]로 반환하세요.",
260
- "trajectory": "당신은 경로 계획 AI입니다. 경로를 [(x1,y1), (x2,y2), ...]로 제시하세요.",
261
- "pointing": "당신은 지점 지정 시스템입니다. 위치를 [(x1,y1), (x2,y2), ...]로 반환하세요."
262
  }
263
 
264
  system_prompt = system_prompts.get(task_type, system_prompts["general"])
265
 
266
  # Chain-of-Thought 추가 (선택적)
267
  if enable_thinking:
268
- system_prompt += "\n\n추론 과정을 <thinking></thinking> 태그 안에 작성 후 최종 답변을 제시하세요."
269
 
270
  # 웹 검색 수행
271
  combined_system = system_prompt
@@ -314,14 +321,25 @@ Step_n: xxx""",
314
  do_sample=True,
315
  temperature=0.7,
316
  top_p=0.9,
 
 
317
  )
318
 
 
 
 
319
  # 디코딩
320
- response = processor.decode(outputs[0], skip_special_tokens=True)
 
 
 
 
321
 
322
- # 프롬프트 제거
323
- if "Assistant:" in response:
324
- response = response.split("Assistant:")[-1].strip()
 
 
325
 
326
  return response
327
 
@@ -490,20 +508,6 @@ with gr.Blocks(title="🤖 로봇 시각 시스템 (Gemma3-4B)", css=css) as dem
490
  </div>
491
  """)
492
 
493
- gr.HTML("""
494
- <div class="info-box">
495
- <h4>🌟 시스템 특징:</h4>
496
- <ul>
497
- <li>🖼️ 고급 이미지/비디오 분석 (Gemma3-4B VLM)</li>
498
- <li>📋 다단계 작업 계획 및 추론</li>
499
- <li>📍 정밀한 객체 위치 파악 (Grounding)</li>
500
- <li>🤏 로봇 파지점 분석 (Affordance)</li>
501
- <li>🛤️ 경로 계획 (Trajectory Planning)</li>
502
- <li>🔍 실시간 웹 검색 통합</li>
503
- <li>🔄 10초마다 자동 캡처 및 분석</li>
504
- </ul>
505
- </div>
506
- """)
507
 
508
  with gr.Row():
509
  # 왼쪽: 웹캠 및 입력
@@ -561,7 +565,7 @@ with gr.Blocks(title="🤖 로봇 시각 시스템 (Gemma3-4B)", css=css) as dem
561
  task_prompt = gr.Textbox(
562
  label="작업 설명 / 질문",
563
  placeholder="예: 테이블 위의 컵을 잡아서 싱크대에 놓기",
564
- value=" 장면에서 로봇이 수행할 수 있는 작업을 분석하세요.",
565
  lines=2
566
  )
567
 
@@ -582,7 +586,7 @@ with gr.Blocks(title="🤖 로봇 시각 시스템 (Gemma3-4B)", css=css) as dem
582
  label="최대 토큰 수",
583
  minimum=100,
584
  maximum=4096,
585
- value=250, # 기본값 250으로 변경
586
  step=50
587
  )
588
 
@@ -669,9 +673,10 @@ with gr.Blocks(title="🤖 로봇 시각 시스템 (Gemma3-4B)", css=css) as dem
669
  "trajectory": "경로 계획"
670
  }
671
 
672
- formatted_result = f"""🤖 {task_names.get(task_type, '분석')} 결과 ({timestamp}):
673
-
674
- {result}"""
 
675
 
676
  complete_status = '<div class="status-box" style="background:#d4edda; color:#155724;">✅ 분석 완료!</div>'
677
  return formatted_result, complete_status
@@ -700,9 +705,10 @@ with gr.Blocks(title="🤖 로봇 시각 시스템 (Gemma3-4B)", css=css) as dem
700
  max_new_tokens=tokens
701
  )
702
 
703
- formatted_result = f"""🔄 자동 분석 ({timestamp}):
704
-
705
- {result}"""
 
706
 
707
  return (
708
  webcam_frame,
 
1
+ #!/usr/bin/env python3
2
+ # 현재 app.py는 양자화 테스트 모델 적용이다.
3
+
4
  #!/usr/bin/env python3
5
 
6
  import os
 
236
  task_type: str = "general",
237
  use_web_search: bool = False,
238
  enable_thinking: bool = False, # 기본값 False로 변경
239
+ max_new_tokens: int = 300 # 장면 설명을 위해 300으로 증가
240
  ) -> str:
241
  """로봇 작업을 위한 이미지 분석"""
242
  global model, processor
 
252
 
253
  # 태스크별 시스템 프롬프트 구성 (더 간결하게)
254
  system_prompts = {
255
+ "general": "당신은 로봇 시각 시스템입니다. 먼저 장면을 1-2줄로 설명하고, 핵심 내용을 간결하게 분석하세요.",
256
  "planning": """당신은 로봇 작업 계획 AI입니다.
257
+ 먼저 장면 이해를 1-2줄로 설명하고, 그 다음 작업 계획을 작성하세요.
258
+ 형식:
259
+ [장면 이해] 현재 보이는 장면을 1-2줄로 설명
260
+
261
+ [작업 계획]
262
+ Step_1: xxx
263
  Step_2: xxx
264
  Step_n: xxx""",
265
+ "grounding": "당신은 객체 위치 시스템입니다. 먼저 보이는 객체들을 한 줄로 설명하고, 요청된 객체 위치를 [x1, y1, x2, y2]로 반환하세요.",
266
+ "affordance": "당신은 파지점 분석 AI입니다. 먼저 대상 객체를 한 줄로 설명하고, 파지 영역을 [x1, y1, x2, y2]로 반환하세요.",
267
+ "trajectory": "당신은 경로 계획 AI입니다. 먼저 환경을 한 줄로 설명하고, 경로를 [(x1,y1), (x2,y2), ...]로 제시하세요.",
268
+ "pointing": "당신은 지점 지정 시스템입니다. 먼저 참조점들을 한 줄로 설명하고, 위치를 [(x1,y1), (x2,y2), ...]로 반환하세요."
269
  }
270
 
271
  system_prompt = system_prompts.get(task_type, system_prompts["general"])
272
 
273
  # Chain-of-Thought 추가 (선택적)
274
  if enable_thinking:
275
+ system_prompt += "\n\n추론 과정을 <thinking></thinking> 태그 안에 작성 후 최종 답변을 제시하세요. 장면 이해는 추론 과정과 별도로 반드시 포함하세요."
276
 
277
  # 웹 검색 수행
278
  combined_system = system_prompt
 
321
  do_sample=True,
322
  temperature=0.7,
323
  top_p=0.9,
324
+ pad_token_id=processor.tokenizer.pad_token_id,
325
+ eos_token_id=processor.tokenizer.eos_token_id,
326
  )
327
 
328
+ # 입력 토큰 제거하여 출력만 추출
329
+ generated_tokens = outputs[0][inputs.input_ids.shape[1]:]
330
+
331
  # 디코딩
332
+ response = processor.decode(generated_tokens, skip_special_tokens=True).strip()
333
+
334
+ # 프롬프트 제거 및 정리
335
+ # 이미 입력 토큰을 제거했으므로 추가 정리만 수행
336
+ response = response.strip()
337
 
338
+ # 혹시 남아있는 불필요한 텍스트 제거
339
+ if response.startswith("model\n"):
340
+ response = response[6:].strip()
341
+ elif response.startswith("model"):
342
+ response = response[5:].strip()
343
 
344
  return response
345
 
 
508
  </div>
509
  """)
510
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
 
512
  with gr.Row():
513
  # 왼쪽: 웹캠 및 입력
 
565
  task_prompt = gr.Textbox(
566
  label="작업 설명 / 질문",
567
  placeholder="예: 테이블 위의 컵을 잡아서 싱크대에 놓기",
568
+ value="현재 장면을 분석하고 로봇이 수행할 수 있는 작업을 제안하세요.",
569
  lines=2
570
  )
571
 
 
586
  label="최대 토큰 수",
587
  minimum=100,
588
  maximum=4096,
589
+ value=300, # 장면 설명을 위해 300으로 증가
590
  step=50
591
  )
592
 
 
673
  "trajectory": "경로 계획"
674
  }
675
 
676
+ formatted_result = f"""🤖 {task_names.get(task_type, '분석')} 결과 ({timestamp})
677
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
678
+ {result}
679
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"""
680
 
681
  complete_status = '<div class="status-box" style="background:#d4edda; color:#155724;">✅ 분석 완료!</div>'
682
  return formatted_result, complete_status
 
705
  max_new_tokens=tokens
706
  )
707
 
708
+ formatted_result = f"""🔄 자동 분석 완료 ({timestamp})
709
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
710
+ {result}
711
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"""
712
 
713
  return (
714
  webcam_frame,