Spaces:
Sleeping
Sleeping
File size: 907 Bytes
d32c870 6af50d2 a9e9652 6af50d2 a4651cd 6af50d2 574bf85 1f502b7 d32c870 6af50d2 |
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 |
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() |