Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,403 +1,166 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from dotenv import load_dotenv
|
| 3 |
-
import gradio as gr
|
| 4 |
-
import pandas as pd
|
| 5 |
-
import json
|
| 6 |
-
from datetime import datetime
|
| 7 |
import torch
|
| 8 |
-
|
| 9 |
import spaces
|
|
|
|
|
|
|
| 10 |
from threading import Thread
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 14 |
MODEL_ID = "CohereForAI/c4ai-command-r7b-12-2024"
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
return_tensors="pt",
|
| 77 |
-
padding=True,
|
| 78 |
-
truncation=True,
|
| 79 |
-
max_length=4096
|
| 80 |
-
)
|
| 81 |
-
|
| 82 |
-
# 모든 텐서를 GPU로 이동
|
| 83 |
-
input_ids = inputs.input_ids.to(self.model.device)
|
| 84 |
-
attention_mask = inputs.attention_mask.to(self.model.device)
|
| 85 |
-
|
| 86 |
-
# 생성
|
| 87 |
-
with torch.no_grad():
|
| 88 |
-
outputs = self.model.generate(
|
| 89 |
-
input_ids=input_ids,
|
| 90 |
-
attention_mask=attention_mask,
|
| 91 |
-
max_new_tokens=max_tokens,
|
| 92 |
-
do_sample=True,
|
| 93 |
-
temperature=temperature,
|
| 94 |
-
top_p=top_p,
|
| 95 |
-
pad_token_id=self.tokenizer.pad_token_id,
|
| 96 |
-
eos_token_id=self.tokenizer.eos_token_id,
|
| 97 |
-
num_return_sequences=1
|
| 98 |
-
)
|
| 99 |
-
|
| 100 |
-
# 디코딩 전에 CPU로 이동
|
| 101 |
-
outputs = outputs.cpu()
|
| 102 |
-
generated_text = self.tokenizer.decode(
|
| 103 |
-
outputs[0][input_ids.shape[1]:],
|
| 104 |
-
skip_special_tokens=True
|
| 105 |
-
)
|
| 106 |
-
|
| 107 |
-
# 단어 단위로 스트리밍
|
| 108 |
-
words = generated_text.split()
|
| 109 |
-
for word in words:
|
| 110 |
-
yield type('Response', (), {
|
| 111 |
-
'choices': [type('Choice', (), {
|
| 112 |
-
'delta': {'content': word + " "}
|
| 113 |
-
})()]
|
| 114 |
-
})()
|
| 115 |
-
|
| 116 |
-
except Exception as e:
|
| 117 |
-
print(f"응답 생성 중 오류 발생: {e}")
|
| 118 |
-
raise Exception(f"응답 생성 실패: {e}")
|
| 119 |
-
|
| 120 |
-
class ChatHistory:
|
| 121 |
-
def __init__(self):
|
| 122 |
-
self.history = []
|
| 123 |
-
self.history_file = "/tmp/chat_history.json"
|
| 124 |
-
self.load_history()
|
| 125 |
-
|
| 126 |
-
def add_conversation(self, user_msg: str, assistant_msg: str):
|
| 127 |
-
conversation = {
|
| 128 |
-
"timestamp": datetime.now().isoformat(),
|
| 129 |
-
"messages": [
|
| 130 |
-
{"role": "user", "content": user_msg},
|
| 131 |
-
{"role": "assistant", "content": assistant_msg}
|
| 132 |
-
]
|
| 133 |
-
}
|
| 134 |
-
self.history.append(conversation)
|
| 135 |
-
self.save_history()
|
| 136 |
-
|
| 137 |
-
def format_for_display(self):
|
| 138 |
-
formatted = []
|
| 139 |
-
for conv in self.history:
|
| 140 |
-
formatted.append([
|
| 141 |
-
conv["messages"][0]["content"],
|
| 142 |
-
conv["messages"][1]["content"]
|
| 143 |
-
])
|
| 144 |
-
return formatted
|
| 145 |
-
|
| 146 |
-
def get_messages_for_api(self):
|
| 147 |
-
messages = []
|
| 148 |
-
for conv in self.history:
|
| 149 |
-
messages.extend([
|
| 150 |
-
{"role": "user", "content": conv["messages"][0]["content"]},
|
| 151 |
-
{"role": "assistant", "content": conv["messages"][1]["content"]}
|
| 152 |
-
])
|
| 153 |
-
return messages
|
| 154 |
-
|
| 155 |
-
def clear_history(self):
|
| 156 |
-
self.history = []
|
| 157 |
-
self.save_history()
|
| 158 |
-
|
| 159 |
-
def save_history(self):
|
| 160 |
-
try:
|
| 161 |
-
with open(self.history_file, 'w', encoding='utf-8') as f:
|
| 162 |
-
json.dump(self.history, f, ensure_ascii=False, indent=2)
|
| 163 |
-
except Exception as e:
|
| 164 |
-
print(f"히스토리 저장 실패: {e}")
|
| 165 |
-
|
| 166 |
-
def load_history(self):
|
| 167 |
-
try:
|
| 168 |
-
if os.path.exists(self.history_file):
|
| 169 |
-
with open(self.history_file, 'r', encoding='utf-8') as f:
|
| 170 |
-
self.history = json.load(f)
|
| 171 |
-
except Exception as e:
|
| 172 |
-
print(f"히스토리 로드 실패: {e}")
|
| 173 |
-
self.history = []
|
| 174 |
-
|
| 175 |
-
# 전역 인스턴스 생성
|
| 176 |
-
chat_history = ChatHistory()
|
| 177 |
-
model_manager = ModelManager()
|
| 178 |
-
|
| 179 |
-
def analyze_file_content(content, file_type):
|
| 180 |
-
"""Analyze file content and return structural summary"""
|
| 181 |
-
if file_type in ['parquet', 'csv']:
|
| 182 |
-
try:
|
| 183 |
-
lines = content.split('\n')
|
| 184 |
-
header = lines[0]
|
| 185 |
-
columns = header.count('|') - 1
|
| 186 |
-
rows = len(lines) - 3
|
| 187 |
-
return f"📊 데이터셋 구조: {columns}개 컬럼, {rows}개 데이터"
|
| 188 |
-
except:
|
| 189 |
-
return "❌ 데이터셋 구조 분석 실패"
|
| 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 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
try:
|
| 264 |
-
# 첫 메시지일 때 모델 로딩
|
| 265 |
-
model_manager.ensure_model_loaded()
|
| 266 |
-
|
| 267 |
-
if uploaded_file:
|
| 268 |
-
content, file_type = read_uploaded_file(uploaded_file)
|
| 269 |
-
if file_type == "error":
|
| 270 |
-
error_message = content
|
| 271 |
-
chat_history.add_conversation(message, error_message)
|
| 272 |
-
return "", history + [[message, error_message]]
|
| 273 |
-
|
| 274 |
-
file_summary = analyze_file_content(content, file_type)
|
| 275 |
-
|
| 276 |
-
if file_type in ['parquet', 'csv']:
|
| 277 |
-
system_message += f"\n\n파일 내용:\n```markdown\n{content}\n```"
|
| 278 |
-
else:
|
| 279 |
-
system_message += f"\n\n파일 내용:\n```\n{content}\n```"
|
| 280 |
-
|
| 281 |
-
if message == "파일 분석을 시작합니다...":
|
| 282 |
-
message = f"""[파일 구조 분석] {file_summary}
|
| 283 |
-
다음 관점에서 도움을 드리겠습니다:
|
| 284 |
-
1. 📋 전반적인 내용 파악
|
| 285 |
-
2. 💡 주요 특징 설명
|
| 286 |
-
3. 🎯 실용적인 활용 방안
|
| 287 |
-
4. ✨ 개선 제안
|
| 288 |
-
5. 💬 추가 질문이나 필요한 설명"""
|
| 289 |
-
|
| 290 |
-
messages = [{"role": "system", "content": system_prefix + system_message}]
|
| 291 |
-
|
| 292 |
-
if history:
|
| 293 |
-
for user_msg, assistant_msg in history:
|
| 294 |
-
messages.append({"role": "user", "content": user_msg})
|
| 295 |
-
messages.append({"role": "assistant", "content": assistant_msg})
|
| 296 |
-
|
| 297 |
-
messages.append({"role": "user", "content": message})
|
| 298 |
-
|
| 299 |
-
partial_message = ""
|
| 300 |
-
|
| 301 |
-
for response in model_manager.generate_response(
|
| 302 |
-
messages,
|
| 303 |
-
max_tokens=max_tokens,
|
| 304 |
-
temperature=temperature,
|
| 305 |
-
top_p=top_p
|
| 306 |
-
):
|
| 307 |
-
token = response.choices[0].delta.get('content', '')
|
| 308 |
-
if token:
|
| 309 |
-
partial_message += token
|
| 310 |
-
current_history = history + [[message, partial_message]]
|
| 311 |
-
yield "", current_history
|
| 312 |
-
|
| 313 |
-
chat_history.add_conversation(message, partial_message)
|
| 314 |
-
|
| 315 |
-
except Exception as e:
|
| 316 |
-
error_msg = f"❌ 오류가 발생했습니다: {str(e)}"
|
| 317 |
-
chat_history.add_conversation(message, error_msg)
|
| 318 |
-
yield "", history + [[message, error_msg]]
|
| 319 |
-
|
| 320 |
-
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", title="GiniGEN 🤖") as demo:
|
| 321 |
-
initial_history = chat_history.format_for_display()
|
| 322 |
-
with gr.Row():
|
| 323 |
-
with gr.Column(scale=2):
|
| 324 |
-
chatbot = gr.Chatbot(
|
| 325 |
-
value=initial_history,
|
| 326 |
-
height=600,
|
| 327 |
-
label="대화창 💬",
|
| 328 |
-
show_label=True
|
| 329 |
-
)
|
| 330 |
-
|
| 331 |
-
msg = gr.Textbox(
|
| 332 |
-
label="메시지 입력",
|
| 333 |
-
show_label=False,
|
| 334 |
-
placeholder="무엇이든 물어보세요... 💭",
|
| 335 |
-
container=False
|
| 336 |
-
)
|
| 337 |
-
with gr.Row():
|
| 338 |
-
clear = gr.ClearButton([msg, chatbot], value="대화내용 지우기")
|
| 339 |
-
send = gr.Button("보내기 📤")
|
| 340 |
-
|
| 341 |
-
with gr.Column(scale=1):
|
| 342 |
-
gr.Markdown("### GiniGEN 🤖 [파일 업로드] 📁\n지원 형식: 텍스트, 코드, CSV, Parquet 파일")
|
| 343 |
-
file_upload = gr.File(
|
| 344 |
-
label="파일 선택",
|
| 345 |
-
file_types=["text", ".csv", ".parquet"],
|
| 346 |
-
type="filepath"
|
| 347 |
-
)
|
| 348 |
-
|
| 349 |
-
with gr.Accordion("고급 설정 ⚙️", open=False):
|
| 350 |
-
system_message = gr.Textbox(label="시스템 메시지 📝", value="")
|
| 351 |
-
max_tokens = gr.Slider(minimum=1, maximum=8000, value=4000, label="최대 토큰 수 📊")
|
| 352 |
-
temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="창의성 수준 🌡️")
|
| 353 |
-
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="응답 다양성 📈")
|
| 354 |
-
|
| 355 |
-
gr.Examples(
|
| 356 |
examples=[
|
| 357 |
-
["
|
| 358 |
-
["
|
| 359 |
-
["
|
| 360 |
-
["
|
| 361 |
-
["
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
],
|
| 363 |
-
|
| 364 |
-
)
|
| 365 |
-
|
| 366 |
-
def clear_chat():
|
| 367 |
-
chat_history.clear_history()
|
| 368 |
-
return None, None
|
| 369 |
-
|
| 370 |
-
msg.submit(
|
| 371 |
-
chat,
|
| 372 |
-
inputs=[msg, chatbot, file_upload, system_message, max_tokens, temperature, top_p],
|
| 373 |
-
outputs=[msg, chatbot]
|
| 374 |
-
)
|
| 375 |
-
|
| 376 |
-
send.click(
|
| 377 |
-
chat,
|
| 378 |
-
inputs=[msg, chatbot, file_upload, system_message, max_tokens, temperature, top_p],
|
| 379 |
-
outputs=[msg, chatbot]
|
| 380 |
-
)
|
| 381 |
-
|
| 382 |
-
clear.click(
|
| 383 |
-
clear_chat,
|
| 384 |
-
outputs=[msg, chatbot]
|
| 385 |
-
)
|
| 386 |
-
|
| 387 |
-
file_upload.change(
|
| 388 |
-
lambda: "파일 분석을 시작합니다...",
|
| 389 |
-
outputs=msg
|
| 390 |
-
).then(
|
| 391 |
-
chat,
|
| 392 |
-
inputs=[msg, chatbot, file_upload, system_message, max_tokens, temperature, top_p],
|
| 393 |
-
outputs=[msg, chatbot]
|
| 394 |
)
|
| 395 |
|
| 396 |
if __name__ == "__main__":
|
| 397 |
-
demo.launch(
|
| 398 |
-
share=False,
|
| 399 |
-
show_error=True,
|
| 400 |
-
server_name="0.0.0.0",
|
| 401 |
-
server_port=7860,
|
| 402 |
-
max_threads=1
|
| 403 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
import spaces
|
| 4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 5 |
+
import os
|
| 6 |
from threading import Thread
|
| 7 |
+
import random
|
| 8 |
+
from datasets import load_dataset
|
| 9 |
|
| 10 |
+
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
|
|
|
| 11 |
MODEL_ID = "CohereForAI/c4ai-command-r7b-12-2024"
|
| 12 |
+
MODELS = os.environ.get("MODELS")
|
| 13 |
+
MODEL_NAME = MODEL_ID.split("/")[-1]
|
| 14 |
+
|
| 15 |
+
TITLE = "<h1><center>새로운 일본어 LLM 모델 웹 UI</center></h1>"
|
| 16 |
+
|
| 17 |
+
DESCRIPTION = f"""
|
| 18 |
+
<h3>모델: <a href="https://huggingface.co/CohereForAI/c4ai-command-r7b-12-2024">CohereForAI/c4ai-command-r7b-12-2024</a></h3>
|
| 19 |
+
<center>
|
| 20 |
+
<p>
|
| 21 |
+
<br>
|
| 22 |
+
cc-by-nc
|
| 23 |
+
</p>
|
| 24 |
+
</center>
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
CSS = """
|
| 28 |
+
.duplicate-button {
|
| 29 |
+
margin: auto !important;
|
| 30 |
+
color: white !important;
|
| 31 |
+
background: black !important;
|
| 32 |
+
border-radius: 100vh !important;
|
| 33 |
+
}
|
| 34 |
+
h3 {
|
| 35 |
+
text-align: center;
|
| 36 |
+
}
|
| 37 |
+
.chatbox .messages .message.user {
|
| 38 |
+
background-color: #e1f5fe;
|
| 39 |
+
}
|
| 40 |
+
.chatbox .messages .message.bot {
|
| 41 |
+
background-color: #eeeeee;
|
| 42 |
+
}
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
# 모델과 토크나이저 로드
|
| 46 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 47 |
+
MODEL_ID,
|
| 48 |
+
torch_dtype=torch.bfloat16,
|
| 49 |
+
device_map="auto",
|
| 50 |
+
)
|
| 51 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 52 |
+
|
| 53 |
+
# 데이터셋 로드
|
| 54 |
+
dataset = load_dataset("elyza/ELYZA-tasks-100")
|
| 55 |
+
print(dataset)
|
| 56 |
+
|
| 57 |
+
split_name = "train" if "train" in dataset else "test"
|
| 58 |
+
examples_list = list(dataset[split_name])
|
| 59 |
+
examples = random.sample(examples_list, 50)
|
| 60 |
+
example_inputs = [[example['input']] for example in examples]
|
| 61 |
+
|
| 62 |
+
@spaces.GPU
|
| 63 |
+
def stream_chat(message: str, history: list, temperature: float, max_new_tokens: int, top_p: float, top_k: int, penalty: float):
|
| 64 |
+
print(f'message is - {message}')
|
| 65 |
+
print(f'history is - {history}')
|
| 66 |
+
conversation = []
|
| 67 |
+
for prompt, answer in history:
|
| 68 |
+
conversation.extend([{"role": "user", "content": prompt}, {"role": "assistant", "content": answer}])
|
| 69 |
+
conversation.append({"role": "user", "content": message})
|
| 70 |
+
|
| 71 |
+
input_ids = tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
|
| 72 |
+
inputs = tokenizer(input_ids, return_tensors="pt").to(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
streamer = TextIteratorStreamer(tokenizer, timeout=10., skip_prompt=True, skip_special_tokens=True)
|
| 75 |
+
|
| 76 |
+
generate_kwargs = dict(
|
| 77 |
+
inputs,
|
| 78 |
+
streamer=streamer,
|
| 79 |
+
top_k=top_k,
|
| 80 |
+
top_p=top_p,
|
| 81 |
+
repetition_penalty=penalty,
|
| 82 |
+
max_new_tokens=max_new_tokens,
|
| 83 |
+
do_sample=True,
|
| 84 |
+
temperature=temperature,
|
| 85 |
+
eos_token_id=[255001],
|
| 86 |
+
)
|
| 87 |
|
| 88 |
+
thread = Thread(target=model.generate, kwargs=generate_kwargs)
|
| 89 |
+
thread.start()
|
| 90 |
+
|
| 91 |
+
buffer = ""
|
| 92 |
+
for new_text in streamer:
|
| 93 |
+
buffer += new_text
|
| 94 |
+
yield buffer
|
| 95 |
+
|
| 96 |
+
chatbot = gr.Chatbot(height=500)
|
| 97 |
+
|
| 98 |
+
with gr.Blocks(css=CSS) as demo:
|
| 99 |
+
gr.HTML(TITLE)
|
| 100 |
+
gr.HTML(DESCRIPTION)
|
| 101 |
+
gr.ChatInterface(
|
| 102 |
+
fn=stream_chat,
|
| 103 |
+
chatbot=chatbot,
|
| 104 |
+
fill_height=True,
|
| 105 |
+
theme="soft",
|
| 106 |
+
additional_inputs_accordion=gr.Accordion(label="⚙️ 매개변수", open=False, render=False),
|
| 107 |
+
additional_inputs=[
|
| 108 |
+
gr.Slider(
|
| 109 |
+
minimum=0,
|
| 110 |
+
maximum=1,
|
| 111 |
+
step=0.1,
|
| 112 |
+
value=0.8,
|
| 113 |
+
label="온도",
|
| 114 |
+
render=False,
|
| 115 |
+
),
|
| 116 |
+
gr.Slider(
|
| 117 |
+
minimum=128,
|
| 118 |
+
maximum=1000000,
|
| 119 |
+
step=1,
|
| 120 |
+
value=100000,
|
| 121 |
+
label="최대 토큰 수",
|
| 122 |
+
render=False,
|
| 123 |
+
),
|
| 124 |
+
gr.Slider(
|
| 125 |
+
minimum=0.0,
|
| 126 |
+
maximum=1.0,
|
| 127 |
+
step=0.1,
|
| 128 |
+
value=0.8,
|
| 129 |
+
label="상위 확률",
|
| 130 |
+
render=False,
|
| 131 |
+
),
|
| 132 |
+
gr.Slider(
|
| 133 |
+
minimum=1,
|
| 134 |
+
maximum=20,
|
| 135 |
+
step=1,
|
| 136 |
+
value=20,
|
| 137 |
+
label="상위 K",
|
| 138 |
+
render=False,
|
| 139 |
+
),
|
| 140 |
+
gr.Slider(
|
| 141 |
+
minimum=0.0,
|
| 142 |
+
maximum=2.0,
|
| 143 |
+
step=0.1,
|
| 144 |
+
value=1.0,
|
| 145 |
+
label="반복 패널티",
|
| 146 |
+
render=False,
|
| 147 |
+
),
|
| 148 |
+
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
examples=[
|
| 150 |
+
["아이의 여름방학 과학 프로젝트를 위한 5가지 아이디어를 주세요."],
|
| 151 |
+
["마크다운을 사용하여 브레이크아웃 게임 만들기 튜토리얼을 작성해주세요."],
|
| 152 |
+
["초능력을 가진 주인공의 SF 이야기 시나리오를 작성해주세요. 복선 설정, 테마와 로그라인을 논리적으로 사용해주세요"],
|
| 153 |
+
["아이의 여름방학 자유연구를 위한 5가지 아이디어와 그 방법을 간단히 알려주세요."],
|
| 154 |
+
["퍼즐 게임 스크립트 작성을 위한 조언 부탁드립니다"],
|
| 155 |
+
["마크다운 형식으로 블록 깨기 게임 제작 교과서를 작성해주세요"],
|
| 156 |
+
["실버 川柳를 생각해주세요"],
|
| 157 |
+
["일본어 관용구, 속담에 관한 시험 문제를 만들어주세요"],
|
| 158 |
+
["도라에몽의 등장인물을 알려주세요"],
|
| 159 |
+
["오코노미야키 만드는 방법을 알려주세요"],
|
| 160 |
+
["문제 9.11과 9.9 중 어느 것이 더 큰가요? step by step으로 논리적으로 생각해주세요."],
|
| 161 |
],
|
| 162 |
+
cache_examples=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
)
|
| 164 |
|
| 165 |
if __name__ == "__main__":
|
| 166 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|