chatbotScratch / app.py
neeraj0604's picture
Update app.py
9c4c48f verified
raw
history blame contribute delete
716 Bytes
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()