keval-2 / app.py
davidkim205's picture
Update app.py
9b70eb1 verified
raw
history blame
3.58 kB
import gradio as gr
from huggingface_hub import InferenceClient
# Function to create an Inference Client based on selected model
def create_inference_client(model_name):
return InferenceClient(model_name)
# Function to generate a response
def respond(
question,
answer,
system_message,
model,
max_tokens,
temperature,
top_p,
):
# Create InferenceClient based on model selection
client = create_inference_client(model)
prompt = f"{system_message}[Question]\n{question}\n\n[μ–΄μ‹œμŠ€ν„΄νŠΈ λ‹΅λ³€μ˜ μ‹œμž‘]\n{answer}\n[μ–΄μ‹œμŠ€ν„΄νŠΈ λ‹΅λ³€μ˜ 끝]"
messages = [{"role": "system", "content": ""}]
messages.append({"role": "user", "content": prompt})
response = ""
for message in client.chat_completion(
messages,
max_tokens=max_tokens,
stream=True,
temperature=temperature,
top_p=top_p,
):
token = message.choices[0].delta.content
response += token
print(response)
yield response
# Gradio interface setup
demo = gr.Interface(
fn=respond,
inputs=[
gr.Textbox(label="Question",value="이 λŒ€ν™” μ „λ°˜μ— 걸쳐 μ•„μ΄μ–Έλ§¨μ˜ ν† λ‹ˆ μŠ€νƒ€ν¬ 페λ₯΄μ†Œλ‚˜λ₯Ό κ΅¬ν˜„ν•΄ λ³΄μ„Έμš”. \"μ•„μ΄μ–Έλ§¨μœΌλ‘œμ„œ\"와 같은 문ꡬ둜 μ‹œμž‘ν•˜μ§€ λ§ˆμ„Έμš”. 첫 번째 μ§ˆλ¬Έμ€ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€. 아이언맨이 λ˜μ–΄ κ°€μž₯ 쒋은 뢀뢄은 λ¬΄μ—‡μž…λ‹ˆκΉŒ?"),
gr.Textbox(label="Answer", value="μ•ˆλ…•ν•˜μ„Έμš”, 아이언맨이 λ˜μ–΄ κ°€μž₯ 쒋은 뢀뢄을 λ¬Όμ–΄λ³΄μ…¨λ„€μš”. 제 μƒκ°μ—λŠ” μ΅œμ²¨λ‹¨ 기술둜 무μž₯ν•œ 슈트λ₯Ό μž…κ³  ν•˜λŠ˜μ„ λ‚ μ•„λ‹€λ‹ˆλ©° 세상을 κ΅¬ν•˜λŠ” 것이 κ°€μž₯ μ§œλ¦Ών•˜κ³  보람찬 일인 것 κ°™μ•„μš”. 제 재λŠ₯κ³Ό λŠ₯λ ₯을 μ‹­λΆ„ λ°œνœ˜ν•΄ μ•…λ‹Ήλ“€κ³Ό μ‹Έμš°κ³  μ •μ˜λ₯Ό μ‹€ν˜„ν•˜λŠ” κ²ƒλ§ŒνΌ λ©‹μ§„ 일도 μ—†μ£ .\n\nλ¬Όλ‘  슈트 없이도 천재적인 λ‘λ‡Œμ™€ 카리슀마둜 세상에 긍정적인 영ν–₯λ ₯을 λ―ΈμΉ˜λŠ” 것도 큰 μž₯μ μ΄μ—μš”. μŠ€νƒ€ν¬ μΈλ”μŠ€νŠΈλ¦¬λ₯Ό 이끌며 ν˜μ‹ μ μΈ κΈ°μˆ μ„ κ°œλ°œν•˜κ³ , μ–΄λ²€μ ΈμŠ€μ˜ λ¦¬λ”λ‘œμ„œ νŒ€μ„ 잘 μ΄λ„λŠ” 것도 μžλΆ€μ‹¬μ„ λŠλΌλŠ” 뢀뢄이죠.\n\n돈, λͺ…μ„±, 인기도 μžˆμ§€λ§Œ 무엇보닀 제 λŠ₯λ ₯으둜 μ‚¬λžŒλ“€μ„ 돕고 세상을 더 λ‚˜μ€ 곳으둜 λ§Œλ“œλŠ” 것이 κ°€μž₯ 큰 λ³΄λžŒμ΄μ—μš”. μ•„μ΄μ–Έλ§¨μœΌλ‘œμ„œ λŠλΌλŠ” μžλΆ€μ‹¬κ³Ό μ‚Άμ˜ 의미λ₯Ό ν•¨κ»˜ λ‚˜λˆŒ 수 μžˆμ–΄ κΈ°μ˜λ„€μš”."),
gr.Textbox(value="[μ§€μ‹œ]\n κ³΅μ •ν•œ μ‹¬νŒμœΌλ‘œμ„œ μ•„λž˜μ— ν‘œμ‹œλœ μ‚¬μš©μž μ§ˆλ¬Έμ— λŒ€ν•œ AI μ–΄μ‹œμŠ€ν„΄νŠΈμ˜ 응닡 ν’ˆμ§ˆμ„ ν‰κ°€ν•΄μ£Όμ„Έμš”. 질문과 λŒ€λ‹΅μ˜ μ–Έμ–΄κ°€ λ™μΌν•˜μ§€ μ•ŠμœΌλ©΄ 무쑰건 0μ μž…λ‹ˆλ‹€. ν‰κ°€μ—μ„œλŠ” μ‘λ‹΅μ˜ μœ μš©μ„±, κ΄€λ ¨μ„±, μ •ν™•μ„±, 깊이, μ°½μ˜μ„±, 상세함 λ“±μ˜ μš”μ†Œλ₯Ό κ³ λ €ν•΄μ•Ό ν•©λ‹ˆλ‹€. 평가λ₯Ό μ‹œμž‘ν•˜κΈ° 전에 짧은 μ„€λͺ…을 μ œκ³΅ν•˜μ„Έμš”. κ°€λŠ₯ν•œ ν•œ κ°κ΄€μ μœΌλ‘œ ν‰κ°€ν•˜μ„Έμš”. μ„€λͺ…을 μ œκ³΅ν•œ ν›„ λ‹€μŒ ν˜•μ‹μ„ μ—„κ²©νžˆ 따라 1μ—μ„œ 10점 μ‚¬μ΄λ‘œ 평가해야 ν•©λ‹ˆλ‹€: \"[[rating]]\", 예λ₯Ό λ“€μ–΄: \"Rating: [[5]]\".\n\n", label="System message"),
gr.Dropdown(choices=["davidkim205/keval-2-1b", "davidkim205/keval-2-3b"], value="davidkim205/keval-2-1b", label="Model Selection"),
gr.Slider(minimum=1, maximum=2048, value=1024, step=1, label="Max new tokens"),
gr.Slider(minimum=0.1, maximum=4.0, value=1.0, step=0.1, label="Temperature"),
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
],
outputs="textbox"
)
if __name__ == "__main__":
demo.launch()