import gradio as gr from transformers import pipeline, AutoTokenizer, AutoModelForQuestionAnswering # Hugging Face 모델 로드 model_name = "distilbert-base-cased-distilled-squad" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForQuestionAnswering.from_pretrained(model_name) qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer) # Gradio 인터페이스 정의 iface = gr.Interface( fn=lambda question: qa_pipeline(question=question, context=context)["answer"], inputs=gr.Textbox(label="Enter a question"), outputs="text", live=True, ) # 인터페이스 실행 iface.launch()