Spaces:
Sleeping
Sleeping
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='ahmadmac/Trained-T5-large', | |
max_length=60, | |
do_sample=True, | |
temperature=1.0 | |
) | |
llm = HuggingFacePipeline(pipeline=pipe) | |
prompt_template = """ you are a highly knownlegdable AI assistant.Engage in a conversation with the user.Your main is to provide clear and informative answer to the user questions. | |
User: {question} | |
Assistant:""" | |
prompt = PromptTemplate(template=prompt_template, input_variables=["question"]) | |
chain = LLMChain(llm=llm, prompt=prompt) | |
def chatbot(question,chat_history): | |
response = chain.run(question) | |
return response | |
demo = gr.ChatInterface( | |
fn=chatbot, | |
title="Chatbot", | |
description="AI Assistant!!" | |
) | |
demo.launch() |