abhinand2's picture
Update app.py
e6125fa verified
raw
history blame
1.69 kB
import gradio as gr
from db import get_db
from chain import get_chain
vectordb = get_db(
chunk_size=1000,
chunk_overlap=200,
model_path = 'intfloat/multilingual-e5-large-instruct',
)
chain = get_chain(
vectordb,
repo_id="HuggingFaceH4/zephyr-7b-beta",
task="text-generation",
max_new_tokens=512,
top_k=30,
temperature=0.1,
repetition_penalty=1.03,
search_type="mmr",
k=3,
fetch_k=5,
template="""Use the following sentences of context to answer the question at the end.
If you don't know the answer, that is if the answer is not in the context, then just say that you don't know, don't try to make up an answer.
Always say "Thanks for asking!" at the end of the answer.
{context}
Question: {question}
Helpful Answer:"""
)
def respond(
question,
_, # Ignore the message history parameter since we are doing one-off invocations
system_message,
max_tokens,
temperature,
top_p,
):
return rag_chain.invoke({'question': question})
"""
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
"""
demo = gr.ChatInterface(
respond,
additional_inputs=[
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
gr.Slider(
minimum=0.1,
maximum=1.0,
value=0.95,
step=0.05,
label="Top-p (nucleus sampling)",
),
],
)
if __name__ == "__main__":
demo.launch()