File size: 946 Bytes
1b1588f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()