File size: 1,197 Bytes
c4be697
2a26a73
ccd354a
c4be697
e8f4525
 
d3ba574
91a2093
2a26a73
 
9ebac62
8d768b7
2a26a73
 
e8f4525
d3ba574
c4be697
67881e0
c4be697
 
9af1238
f092898
 
c4be697
f092898
 
 
 
 
91a2093
f092898
e777dab
 
f092898
 
 
 
a6de600
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
from langchain import HuggingFaceHub, PromptTemplate, LLMChain
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
import gradio as gr
from getpass import getpass
import os

template = """Question: {question}
------------------
Answer: Let's think step by step."""

prompt = PromptTemplate(template=template, input_variables=["history"])

# Callbacks support token-wise streaming
callbacks = [StreamingStdOutCallbackHandler()]
# Instantiate the Hugging Face model
repo_id = "gpt2"  # Replace with the desired model
llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature": 0, "max_length": 64})

# Initialize the  chain
llm_chain = LLMChain(prompt=prompt, llm=llm)

# Define the Gradio interface
def chatbot_interface(input_text):
    response = llm_chain.run(input_text)
    return response

# Define the Gradio app
gradio_app = gr.Interface(
    fn=chatbot_interface,
    inputs=gr.inputs.Textbox(label="Say something..."),
    outputs=gr.outputs.Textbox(),
    title="ConversationChain Chatbot",
    description="A chatbot interface powered by ConversationChain and Hugging Face.",
)

# Run the Gradio app
if __name__ == "__main__":
    gradio_app.launch()