Spaces:
Sleeping
Sleeping
File size: 2,103 Bytes
e763e8a 0d179e3 11a9727 e763e8a 0d179e3 3b344a7 d14928c fed1aac bd92b29 fed1aac 95915d0 074e5e6 0fd1475 237a3be c88c382 a148c7b 3c20b70 3c4dfb1 0b1ab4b 3c4dfb1 2bc028d b6c9ea3 0d179e3 |
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
from omegaconf import OmegaConf
from query import VectaraQuery
import os
import gradio as gr
def isTrue(x) -> bool:
if isinstance(x, bool):
return x
return x.strip().lower() == 'true'
corpus_ids = str(os.environ['corpus_ids']).split(',')
cfg = OmegaConf.create({
'customer_id': str(os.environ['customer_id']),
'corpus_ids': corpus_ids,
'api_key': str(os.environ['api_key']),
'title': os.environ['title'],
'description': os.environ['description'],
'source_data_desc': os.environ['source_data_desc'],
'streaming': isTrue(os.environ.get('streaming', False)),
'prompt_name': os.environ.get('prompt_name', None)
})
vq = VectaraQuery(cfg.api_key, cfg.customer_id, cfg.corpus_ids, cfg.prompt_name)
def respond(message, history):
if cfg.streaming:
# Call stream response and stream output
stream = vq.submit_query_streaming(message)
outputs = ""
for output in stream:
outputs += output
yield outputs
else:
# Call non-stream response and return message output
response = vq.submit_query(message)
yield response
cfg.title = f'''<h1 style="text-align: center;">{cfg.title}</h1>'''
cfg.description = f'''<center> <h2>{cfg.description}</h2>
<br>
This demo uses Retrieval Augmented Generation to ask questions about {cfg.source_data_desc}</center>'''
image_html = '''
<img src="https://github.com/david-oplatka/chatbot-streamlit/blob/main/Vectara-logo.png" style="float:left; width:100px; height:50px; margin-right:20px;">
'''
# with gr.Blocks() as demo:
# gr.HTML()
# gr.ChatInterface(respond, title = cfg.title, description = cfg.description,
# chatbot = gr.Chatbot(value = [[None, "How may I help you?"]], scale=3))
with gr.Blocks() as demo:
with gr.Row():
gr.HTML(image_html)
gr.HTML(cfg.title)
gr.HTML(cfg.description)
gr.ChatInterface(respond, chatbot=gr.Chatbot(value=[[None, "How may I help you?"]], scale=3))
if __name__ == "__main__":
demo.launch() |