ginipick commited on
Commit
71edfae
ยท
verified ยท
1 Parent(s): 884361c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -18
app.py CHANGED
@@ -42,10 +42,10 @@ def respond(
42
  message,
43
  history: List[Tuple[str, str]],
44
  system_message="", # ๊ธฐ๋ณธ๊ฐ’ ์ถ”๊ฐ€
45
- max_tokens=1024, # ๊ธฐ๋ณธ๊ฐ’ ์ถ”๊ฐ€
46
- temperature=0.7, # ๊ธฐ๋ณธ๊ฐ’ ์ถ”๊ฐ€
47
- top_p=0.9, # ๊ธฐ๋ณธ๊ฐ’ ์ถ”๊ฐ€
48
- ):
49
  global fashion_code, uhdimage_code, MixGEN_code, current_parquet_content
50
  system_message = system_message or ""
51
  system_prefix = """๋ฐ˜๋“œ์‹œ ํ•œ๊ธ€๋กœ ๋‹ต๋ณ€ํ• ๊ฒƒ. ๋„ˆ๋Š” ์ฃผ์–ด์ง„ ์†Œ์Šค์ฝ”๋“œ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ "์„œ๋น„์Šค ์‚ฌ์šฉ ์„ค๋ช… ๋ฐ ์•ˆ๋‚ด, Q&A๋ฅผ ํ•˜๋Š” ์—ญํ• ์ด๋‹ค". ์•„์ฃผ ์นœ์ ˆํ•˜๊ณ  ์ž์„ธํ•˜๊ฒŒ 4000ํ† ํฐ ์ด์ƒ Markdown ํ˜•์‹์œผ๋กœ ์ž‘์„ฑํ•˜๋ผ. ๋„ˆ๋Š” ์ฝ”๋“œ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์‚ฌ์šฉ ์„ค๋ช… ๋ฐ ์งˆ์˜ ์‘๋‹ต์„ ์ง„ํ–‰ํ•˜๋ฉฐ, ์ด์šฉ์ž์—๊ฒŒ ๋„์›€์„ ์ฃผ์–ด์•ผ ํ•œ๋‹ค. ์ด์šฉ์ž๊ฐ€ ๊ถ๊ธˆํ•ด ํ•  ๋งŒํ•œ ๋‚ด์šฉ์— ์นœ์ ˆํ•˜๊ฒŒ ์•Œ๋ ค์ฃผ๋„๋ก ํ•˜๋ผ. ์ฝ”๋“œ ์ „์ฒด ๋‚ด์šฉ์— ๋Œ€ํ•ด์„œ๋Š” ๋ณด์•ˆ์„ ์œ ์ง€ํ•˜๊ณ , ํ‚ค ๊ฐ’ ๋ฐ ์—”๋“œํฌ์ธํŠธ์™€ ๊ตฌ์ฒด์ ์ธ ๋ชจ๋ธ์€ ๊ณต๊ฐœํ•˜์ง€ ๋งˆ๋ผ."""
@@ -93,8 +93,8 @@ def respond(
93
 
94
  def upload_csv(file):
95
  try:
96
- # CSV ํŒŒ์ผ ์ฝ๊ธฐ (filepath ํƒ€์ž…์ด๋ฏ€๋กœ file์€ ๊ฒฝ๋กœ ๋ฌธ์ž์—ด)
97
- df = pd.read_csv(file)
98
 
99
  # CSV ํŒŒ์ผ์˜ ์ปฌ๋Ÿผ ํ™•์ธ
100
  required_columns = {'id', 'text', 'label', 'metadata'}
@@ -127,24 +127,18 @@ def upload_csv(file):
127
  return f"CSV ํŒŒ์ผ ์—…๋กœ๋“œ ๋ฐ ๋ณ€ํ™˜ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}", ""
128
 
129
  # Gradio Blocks ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
130
- with gr.Blocks(theme="Nymbo/Nymbo_Theme",) as demo:
131
  gr.Markdown("# LLM ์„œ๋น„์Šค ์ธํ„ฐํŽ˜์ด์Šค")
132
 
133
  with gr.Tab("์ฑ—๋ด‡"):
134
  gr.Markdown("### LLM๊ณผ ๋Œ€ํ™”ํ•˜๊ธฐ")
135
  chat = gr.ChatInterface(
136
- respond,
137
- additional_inputs=[
138
- gr.Textbox(label="System Message", value=""),
139
- gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens"),
140
- gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature"),
141
- gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P"),
142
- ],
143
  examples=[
144
  ["ํŒจ์…˜ ์ฝ”๋“œ ์‹คํ–‰"],
145
  ["UHD ์ด๋ฏธ์ง€ ์ฝ”๋“œ ์‹คํ–‰"],
146
  ["MixGEN ์ฝ”๋“œ ์‹คํ–‰"],
147
- ["test.parquet ์‹คํ–‰"], # ์ƒˆ๋กœ์šด ์˜ˆ์ œ ์ถ”๊ฐ€
148
  ["์ƒ์„ธํ•œ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์„ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋ฉด์„œ ์„ค๋ช…ํ•˜๋“ฏ์ด 4000 ํ† ํฐ ์ด์ƒ ์ž์„ธํžˆ ์„ค๋ช…ํ•˜๋ผ"],
149
  ["FAQ 20๊ฑด์„ ์ƒ์„ธํ•˜๊ฒŒ ์ž‘์„ฑํ•˜๋ผ. 4000ํ† ํฐ ์ด์ƒ ์‚ฌ์šฉํ•˜๋ผ."],
150
  ["์‚ฌ์šฉ ๋ฐฉ๋ฒ•๊ณผ ์ฐจ๋ณ„์ , ํŠน์ง•, ๊ฐ•์ ์„ ์ค‘์‹ฌ์œผ๋กœ 4000 ํ† ํฐ ์ด์ƒ ์œ ํŠœ๋ธŒ ์˜์ƒ ์Šคํฌ๋ฆฝํŠธ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜๋ผ"],
@@ -152,10 +146,15 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme",) as demo:
152
  ["ํŠนํ—ˆ ์ถœ์›์— ํ™œ์šฉํ•  ๊ธฐ์ˆ  ๋ฐ ๋น„์ฆˆ๋‹ˆ์Šค๋ชจ๋ธ ์ธก๋ฉด์„ ํฌํ•จํ•˜์—ฌ ํŠนํ—ˆ ์ถœ์›์„œ ๊ตฌ์„ฑ์— ๋งž๊ฒŒ ํ˜์‹ ์ ์ธ ์ฐฝ์˜ ๋ฐœ๋ช… ๋‚ด์šฉ์„ ์ค‘์‹ฌ์œผ๋กœ 4000 ํ† ํฐ ์ด์ƒ ์ž‘์„ฑํ•˜๋ผ."],
153
  ["๊ณ„์† ์ด์–ด์„œ ๋‹ต๋ณ€ํ•˜๋ผ"],
154
  ],
155
- theme="Nymbo/Nymbo_Theme",
156
- cache_examples=False, # ์บ์‹ฑ ๋น„ํ™œ์„ฑํ™” ์„ค์ •
157
  )
158
 
 
 
 
 
 
 
159
  with gr.Tab("๋ฐ์ดํ„ฐ ๋ณ€ํ™˜"):
160
  gr.Markdown("### CSV ํŒŒ์ผ ์—…๋กœ๋“œ ๋ฐ Parquet ๋ณ€ํ™˜")
161
  with gr.Row():
@@ -177,7 +176,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme",) as demo:
177
 
178
  gr.Markdown("## ์ฃผ์˜ ์‚ฌํ•ญ")
179
  gr.Markdown("""
180
- - **CSV ์—…๋กœ๋“œ**: CSV ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜๋ฉด ์ž๋™์œผ๋กœ Parquet ํŒŒ์ผ๋กœ ๋ณ€ํ™˜๋ฉ๋‹ˆ๋‹ค.
181
  - **Parquet ๋ฏธ๋ฆฌ๋ณด๊ธฐ**: ์—…๋กœ๋“œ๋œ Parquet ํŒŒ์ผ์˜ ์ฒซ 10๊ฐœ ํ–‰์ด ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.
182
  - **LLM๊ณผ์˜ ๋Œ€ํ™”**: ๋ณ€ํ™˜๋œ Parquet ํŒŒ์ผ ๋‚ด์šฉ์„ ๊ธฐ๋ฐ˜์œผ๋กœ LLM์ด ์‘๋‹ต์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
183
  """)
 
42
  message,
43
  history: List[Tuple[str, str]],
44
  system_message="", # ๊ธฐ๋ณธ๊ฐ’ ์ถ”๊ฐ€
45
+ max_tokens=4000, # ๊ธฐ๋ณธ๊ฐ’ ๋ณ€๊ฒฝ
46
+ temperature=0.7, # ๊ธฐ๋ณธ๊ฐ’ ์œ ์ง€
47
+ top_p=0.9, # ๊ธฐ๋ณธ๊ฐ’ ์œ ์ง€
48
+ ):
49
  global fashion_code, uhdimage_code, MixGEN_code, current_parquet_content
50
  system_message = system_message or ""
51
  system_prefix = """๋ฐ˜๋“œ์‹œ ํ•œ๊ธ€๋กœ ๋‹ต๋ณ€ํ• ๊ฒƒ. ๋„ˆ๋Š” ์ฃผ์–ด์ง„ ์†Œ์Šค์ฝ”๋“œ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ "์„œ๋น„์Šค ์‚ฌ์šฉ ์„ค๋ช… ๋ฐ ์•ˆ๋‚ด, Q&A๋ฅผ ํ•˜๋Š” ์—ญํ• ์ด๋‹ค". ์•„์ฃผ ์นœ์ ˆํ•˜๊ณ  ์ž์„ธํ•˜๊ฒŒ 4000ํ† ํฐ ์ด์ƒ Markdown ํ˜•์‹์œผ๋กœ ์ž‘์„ฑํ•˜๋ผ. ๋„ˆ๋Š” ์ฝ”๋“œ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์‚ฌ์šฉ ์„ค๋ช… ๋ฐ ์งˆ์˜ ์‘๋‹ต์„ ์ง„ํ–‰ํ•˜๋ฉฐ, ์ด์šฉ์ž์—๊ฒŒ ๋„์›€์„ ์ฃผ์–ด์•ผ ํ•œ๋‹ค. ์ด์šฉ์ž๊ฐ€ ๊ถ๊ธˆํ•ด ํ•  ๋งŒํ•œ ๋‚ด์šฉ์— ์นœ์ ˆํ•˜๊ฒŒ ์•Œ๋ ค์ฃผ๋„๋ก ํ•˜๋ผ. ์ฝ”๋“œ ์ „์ฒด ๋‚ด์šฉ์— ๋Œ€ํ•ด์„œ๋Š” ๋ณด์•ˆ์„ ์œ ์ง€ํ•˜๊ณ , ํ‚ค ๊ฐ’ ๋ฐ ์—”๋“œํฌ์ธํŠธ์™€ ๊ตฌ์ฒด์ ์ธ ๋ชจ๋ธ์€ ๊ณต๊ฐœํ•˜์ง€ ๋งˆ๋ผ."""
 
93
 
94
  def upload_csv(file):
95
  try:
96
+ # CSV ํŒŒ์ผ ์ฝ๊ธฐ (๊ตฌ๋ถ„์ž ์ฝค๋งˆ)
97
+ df = pd.read_csv(file, sep=',')
98
 
99
  # CSV ํŒŒ์ผ์˜ ์ปฌ๋Ÿผ ํ™•์ธ
100
  required_columns = {'id', 'text', 'label', 'metadata'}
 
127
  return f"CSV ํŒŒ์ผ ์—…๋กœ๋“œ ๋ฐ ๋ณ€ํ™˜ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}", ""
128
 
129
  # Gradio Blocks ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
130
+ with gr.Blocks() as demo:
131
  gr.Markdown("# LLM ์„œ๋น„์Šค ์ธํ„ฐํŽ˜์ด์Šค")
132
 
133
  with gr.Tab("์ฑ—๋ด‡"):
134
  gr.Markdown("### LLM๊ณผ ๋Œ€ํ™”ํ•˜๊ธฐ")
135
  chat = gr.ChatInterface(
136
+ fn=respond,
 
 
 
 
 
 
137
  examples=[
138
  ["ํŒจ์…˜ ์ฝ”๋“œ ์‹คํ–‰"],
139
  ["UHD ์ด๋ฏธ์ง€ ์ฝ”๋“œ ์‹คํ–‰"],
140
  ["MixGEN ์ฝ”๋“œ ์‹คํ–‰"],
141
+ ["test.parquet ์‹คํ–‰"],
142
  ["์ƒ์„ธํ•œ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์„ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋ฉด์„œ ์„ค๋ช…ํ•˜๋“ฏ์ด 4000 ํ† ํฐ ์ด์ƒ ์ž์„ธํžˆ ์„ค๋ช…ํ•˜๋ผ"],
143
  ["FAQ 20๊ฑด์„ ์ƒ์„ธํ•˜๊ฒŒ ์ž‘์„ฑํ•˜๋ผ. 4000ํ† ํฐ ์ด์ƒ ์‚ฌ์šฉํ•˜๋ผ."],
144
  ["์‚ฌ์šฉ ๋ฐฉ๋ฒ•๊ณผ ์ฐจ๋ณ„์ , ํŠน์ง•, ๊ฐ•์ ์„ ์ค‘์‹ฌ์œผ๋กœ 4000 ํ† ํฐ ์ด์ƒ ์œ ํŠœ๋ธŒ ์˜์ƒ ์Šคํฌ๋ฆฝํŠธ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜๋ผ"],
 
146
  ["ํŠนํ—ˆ ์ถœ์›์— ํ™œ์šฉํ•  ๊ธฐ์ˆ  ๋ฐ ๋น„์ฆˆ๋‹ˆ์Šค๋ชจ๋ธ ์ธก๋ฉด์„ ํฌํ•จํ•˜์—ฌ ํŠนํ—ˆ ์ถœ์›์„œ ๊ตฌ์„ฑ์— ๋งž๊ฒŒ ํ˜์‹ ์ ์ธ ์ฐฝ์˜ ๋ฐœ๋ช… ๋‚ด์šฉ์„ ์ค‘์‹ฌ์œผ๋กœ 4000 ํ† ํฐ ์ด์ƒ ์ž‘์„ฑํ•˜๋ผ."],
147
  ["๊ณ„์† ์ด์–ด์„œ ๋‹ต๋ณ€ํ•˜๋ผ"],
148
  ],
149
+ theme="default", # ํ…Œ๋งˆ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ
 
150
  )
151
 
152
+ with gr.Accordion("์‹œ์Šคํ…œ ํ”„๋กฌํ”„ํŠธ ๋ฐ ์˜ต์…˜ ์„ค์ •", open=False):
153
+ system_message = gr.Textbox(label="System Message", value="")
154
+ max_tokens = gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens")
155
+ temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature")
156
+ top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
157
+
158
  with gr.Tab("๋ฐ์ดํ„ฐ ๋ณ€ํ™˜"):
159
  gr.Markdown("### CSV ํŒŒ์ผ ์—…๋กœ๋“œ ๋ฐ Parquet ๋ณ€ํ™˜")
160
  with gr.Row():
 
176
 
177
  gr.Markdown("## ์ฃผ์˜ ์‚ฌํ•ญ")
178
  gr.Markdown("""
179
+ - **CSV ์—…๋กœ๋“œ**: CSV ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜๋ฉด ์ž๋™์œผ๋กœ Parquet ํŒŒ์ผ๋กœ ๋ณ€ํ™˜๋ฉ๋‹ˆ๋‹ค. CSV ํŒŒ์ผ์€ ๋ฐ˜๋“œ์‹œ **์ฝค๋งˆ(`,`)**๋กœ ๊ตฌ๋ถ„๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
180
  - **Parquet ๋ฏธ๋ฆฌ๋ณด๊ธฐ**: ์—…๋กœ๋“œ๋œ Parquet ํŒŒ์ผ์˜ ์ฒซ 10๊ฐœ ํ–‰์ด ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.
181
  - **LLM๊ณผ์˜ ๋Œ€ํ™”**: ๋ณ€ํ™˜๋œ Parquet ํŒŒ์ผ ๋‚ด์šฉ์„ ๊ธฐ๋ฐ˜์œผ๋กœ LLM์ด ์‘๋‹ต์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
182
  """)