File size: 660 Bytes
e7f8fa4
 
22f6b09
e7f8fa4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from langchain_huggingface.llms import HuggingFacePipeline
from langchain_core.prompts import PromptTemplate
import gradio as gr

hf = HuggingFacePipeline.from_model_id(
    model_id="gpt2",
    task="text-generation",
    pipeline_kwargs={"max_new_tokens": 100},
)

template = """Question: {question}

Answer: Let's think step by step."""

prompt = PromptTemplate.from_template(template)

chain = prompt | hf

def respond(question,history):
    return chain.invoke({"question": question})

chat_interface = gr.ChatInterface(fn=respond, title="Q&A Chatbot", description="Ask any question and get an answer!")

# Launch the interface
chat_interface.launch()