File size: 752 Bytes
faf23c8 09648c0 faf23c8 09648c0 faf23c8 09648c0 faf23c8 09648c0 faf23c8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import gradio as gr
from transformers import pipeline, set_seed
generator = pipeline("text-generation", model="gpt2")
set_seed(42)
def ask_librarian(user_input):
prompt = f"μ¬μ©μ: {user_input}\nμ¬μ:"
result = generator(prompt, max_new_tokens=60, do_sample=True, temperature=0.8)[0]["generated_text"]
response = result.split("μ¬μ:")[-1].strip()
return response
demo = gr.Interface(
fn=ask_librarian,
inputs=gr.Textbox(lines=3, placeholder="μ±
μΆμ²μ΄λ κΆκΈν κ²μ μ
λ ₯ν΄ λ³΄μΈμ."),
outputs="text",
title="π AI λμκ΄ μ¬μ",
description="μ±
μΆμ², λμ κ΄λ ¨ μ§λ¬Έ, κ°λ¨ν μμμ λ΅λ³νλ AI μ¬μ μ±λ΄μ
λλ€."
)
if __name__ == "__main__":
demo.launch()
|