File size: 716 Bytes
9c4c48f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline
from langchain.llms import HuggingFacePipeline
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain

# Load model
pipe = pipeline("text-generation", model="gpt2", max_length=100)
llm = HuggingFacePipeline(pipeline=pipe)

# Prompt template
prompt = PromptTemplate.from_template("User: {question}\nBot:")
chain = LLMChain(prompt=prompt, llm=llm)

# Gradio chatbot function
def chatbot_response(user_input):
    return chain.run(user_input).strip()

# Gradio UI
ui = gr.Interface(
    fn=chatbot_response,
    inputs="text",
    outputs="text",
    title="🤖 My LangChain Chatbot",
    description="Ask me anything!",
)

ui.launch()