umairahmad89
initial commit
67a91b0
raw
history blame
2.2 kB
import os
from typing import Dict, List
import gradio as gr
from src.main import get_response, add_file
from dotenv import load_dotenv
load_dotenv("./.env")
print(os.environ)
def process_input(message: str, history: List):
response = get_response(message)
history.append((message, response["answer"]))
return (
"",
history,
"\n".join([res.metadata["source"] for res in response["source_documents"]]),
)
def add_to_db(file: gr.File):
add_file(file)
gr.Info("File added to Vector Database")
def main():
with gr.Blocks(title="Hospital Policy", theme="soft") as demo:
gr.HTML(
"""
<div style="display: flex; flex-direction: column; align-items: center; text-align: center; margin-top: 10px;">
<div style="width: 100px; height: 100px; border-radius: 50%; overflow: hidden;">
<img src="/file=static/icon.jpg" alt="Hospital Icon" style="width: 100%; height: 100%; object-fit: cover;">
</div>
<div style="margin-top: 5px; font-size:24px; font-weight: bold;">Hospital Policy</div>
</div>
"""
)
with gr.Tabs():
with gr.Tab(label="Chatbot"):
chatbot = gr.Chatbot(height=300, likeable=True)
message = gr.Textbox(
placeholder="Ask me a yes or no question",
scale=7,
label="Input message",
)
sources = gr.Textbox(label="Sources")
_ = gr.ClearButton([message, chatbot, sources])
message.submit(
process_input,
inputs=[message, chatbot],
outputs=[message, chatbot, sources],
)
# with gr.Tab(label="Add Data"):
# upload_file = gr.File(label="Upload file(PDF, DOCX, Image)")
# upload_file_button = gr.Button(value="Add File to Vector DB")
# upload_file_button.click(add_to_db, inputs=upload_file)
demo.launch(server_name="0.0.0.0", server_port=7777, allowed_paths=["static", "."])
if __name__ == "__main__":
main()