Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from langchain import PromptTemplate, LLMChain
|
| 3 |
+
from langchain_huggingface import HuggingFacePipeline, HuggingFaceEndpoint
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
import os
|
| 6 |
+
#os.environ["HUGGINGFACEHUB_API_TOKEN"]
|
| 7 |
+
pipe = pipeline(
|
| 8 |
+
'text2text-generation',
|
| 9 |
+
model='ahmadmac/Trained-T5-large',
|
| 10 |
+
max_length=60,
|
| 11 |
+
do_sample=True,
|
| 12 |
+
temperature=1.0
|
| 13 |
+
)
|
| 14 |
+
llm = HuggingFacePipeline(pipeline=pipe)
|
| 15 |
+
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.
|
| 16 |
+
User: {question}
|
| 17 |
+
Assistant:"""
|
| 18 |
+
prompt = PromptTemplate(template=prompt_template, input_variables=["question"])
|
| 19 |
+
chain = LLMChain(llm=llm, prompt=prompt)
|
| 20 |
+
def chatbot(question,chat_history):
|
| 21 |
+
response = chain.run(question)
|
| 22 |
+
return response
|
| 23 |
+
demo = gr.ChatInterface(
|
| 24 |
+
fn=chatbot,
|
| 25 |
+
title="Chatbot",
|
| 26 |
+
description="AI Assistant!!"
|
| 27 |
+
)
|
| 28 |
+
demo.launch()
|