openfree commited on
Commit
02953db
·
verified ·
1 Parent(s): eef0ab8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -2
app.py CHANGED
@@ -9,6 +9,7 @@ import torch
9
  import numpy as np
10
  from diffusers import DiffusionPipeline
11
  from transformers import pipeline as hf_pipeline
 
12
 
13
  ##############################################################################
14
  # 1) ZeroGPU 환경 처리 + device, dtype 설정
@@ -78,6 +79,29 @@ def contains_korean(text):
78
  return True
79
  return False
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  ##############################################################################
82
  # 이미지 생성 함수
83
  ##############################################################################
@@ -85,6 +109,11 @@ def generate_design_image(prompt, seed=42, randomize_seed=True, width=1024, heig
85
  original_prompt = prompt
86
  translated = False
87
 
 
 
 
 
 
88
  if contains_korean(prompt):
89
  translation = translator(prompt)
90
  prompt = translation[0]['translation_text']
@@ -492,7 +521,6 @@ with gr.Blocks(
492
  text_input1 = gr.Textbox(label="키워드 1 (필수)", placeholder="예: 스마트폰")
493
  text_input2 = gr.Textbox(label="키워드 2 (선택)", placeholder="예: 인공지능")
494
  text_input3 = gr.Textbox(label="키워드 3 (선택)", placeholder="예: 헬스케어")
495
- # 드롭다운 대신 라디오 버튼으로 카테고리 선택 (모든 옵션이 펼쳐짐)
496
  category_radio = gr.Radio(
497
  label="카테고리 선택",
498
  choices=list(physical_transformation_categories.keys()),
@@ -520,7 +548,6 @@ with gr.Blocks(
520
  idea_output = gr.Markdown(label="아이디어 결과")
521
  generated_image = gr.Image(label="생성된 디자인 이미지", type="pil")
522
 
523
- # 다양한 카테고리가 포함된 예제 (라디오 버튼 입력)
524
  gr.Examples(
525
  examples=[
526
  ["스마트폰", "", "", "공간 이동"],
 
9
  import numpy as np
10
  from diffusers import DiffusionPipeline
11
  from transformers import pipeline as hf_pipeline
12
+ import re
13
 
14
  ##############################################################################
15
  # 1) ZeroGPU 환경 처리 + device, dtype 설정
 
79
  return True
80
  return False
81
 
82
+ ##############################################################################
83
+ # 입력 텍스트 클린징 함수: 한글, 영문, 숫자, 공백 및 일반적인 문장 부호만 허용
84
+ ##############################################################################
85
+ def clean_input_text(text):
86
+ """
87
+ 한글, 영문, 숫자, 공백 및 . , ! ? - : ; ' " 등의 문장 부호만 남기고 제거합니다.
88
+ 필요에 따라 허용할 문자를 조정할 수 있습니다.
89
+ """
90
+ allowed = re.compile(r'[^ㄱ-ㅎ가-힣a-zA-Z0-9\s\.\,\!\?\-\:\;\'\"]')
91
+ cleaned_text = allowed.sub('', text)
92
+ return cleaned_text
93
+
94
+ ##############################################################################
95
+ # 입력 텍스트의 예상치 못한 문자 로그 함수 (디버깅용)
96
+ ##############################################################################
97
+ def log_unexpected_characters(text):
98
+ allowed = re.compile(r'[ㄱ-ㅎ가-힣a-zA-Z0-9\s\.\,\!\?\-\:\;\'\"]')
99
+ unexpected_chars = [char for char in text if not allowed.match(char)]
100
+ if unexpected_chars:
101
+ print("예상치 못한 문자 발견:", set(unexpected_chars))
102
+ else:
103
+ print("입력 텍스트에 예상치 못한 문자는 없습니다.")
104
+
105
  ##############################################################################
106
  # 이미지 생성 함수
107
  ##############################################################################
 
109
  original_prompt = prompt
110
  translated = False
111
 
112
+ # 입력 텍스트 클린징 적용
113
+ prompt = clean_input_text(prompt)
114
+ # 디버깅: 예상치 못한 문자 로그 출력 (필요 시 활성화)
115
+ # log_unexpected_characters(prompt)
116
+
117
  if contains_korean(prompt):
118
  translation = translator(prompt)
119
  prompt = translation[0]['translation_text']
 
521
  text_input1 = gr.Textbox(label="키워드 1 (필수)", placeholder="예: 스마트폰")
522
  text_input2 = gr.Textbox(label="키워드 2 (선택)", placeholder="예: 인공지능")
523
  text_input3 = gr.Textbox(label="키워드 3 (선택)", placeholder="예: 헬스케어")
 
524
  category_radio = gr.Radio(
525
  label="카테고리 선택",
526
  choices=list(physical_transformation_categories.keys()),
 
548
  idea_output = gr.Markdown(label="아이디어 결과")
549
  generated_image = gr.Image(label="생성된 디자인 이미지", type="pil")
550
 
 
551
  gr.Examples(
552
  examples=[
553
  ["스마트폰", "", "", "공간 이동"],