File size: 914 Bytes
580c4c0
269fe98
580c4c0
269fe98
 
580c4c0
269fe98
 
 
 
580c4c0
269fe98
 
 
 
 
 
 
580c4c0
269fe98
 
580c4c0
269fe98
580c4c0
269fe98
5e8231d
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
import gradio as gr
from transformers import pipeline

# 加載Hugging Face上的語意檢索模型
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")

def answer_question(document, question):
    # 模擬基於上傳文件內容進行的問答
    response = qa_pipeline({'question': question, 'context': document})
    return response['answer']

# 定義 Gradio UI
def chat_interface():
    with gr.Blocks() as demo:
        # 文件上傳元件
        document = gr.Textbox(label="Document Text", lines=10, placeholder="Paste the content of the document here...")
        question = gr.Textbox(label="Ask a question about the document")
        answer = gr.Textbox(label="Answer")

        # 按鈕用於觸發回答
        gr.Button("Ask").click(fn=answer_question, inputs=[document, question], outputs=answer)

    return demo

demo = chat_interface()
demo.launch(share=True)