Spaces:
Sleeping
Sleeping
File size: 3,581 Bytes
276eea4 9b70eb1 5c085a0 276eea4 5c085a0 276eea4 5c085a0 276eea4 5c085a0 276eea4 5c085a0 276eea4 5c085a0 276eea4 5c085a0 276eea4 5c085a0 276eea4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 |
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()
|