import gradio as gr from langchain import PromptTemplate, LLMChain from langchain_huggingface import HuggingFacePipeline, HuggingFaceEndpoint from transformers import pipeline import os os.environ["HUGGINGFACEHUB_API_TOKEN"] pipe = pipeline( 'text2text-generation', model='google/flan-t5-small', max_length=60, do_sample=True, temperature=0.9 ) llm = HuggingFacePipeline(pipeline=pipe) prompt_template = """AI assistant. I am always here to help. User: {question} Assistant:""" prompt = PromptTemplate(template=prompt_template, input_variables=["question"]) chain = LLMChain(llm=llm, prompt=prompt) def chatbot(question): response = chain.run(question) return response demo = gr.ChatInterface( fn=chatbot, inputs=gr.Textbox(lines=2, label="Question"), outputs=gr.Textbox(label="Answer"), title="Chatbot", description="Helpful AI Assistant!!" ) demo.launch()