devalbot / app.py
gtani's picture
Refactor chat functionality and update dependencies
f904c62
raw
history blame
1.64 kB
import gradio as gr
from bedrock_client import claude_llm
from utils import load_users
AUTHS = load_users('user.csv')
def chat(user_message, history):
# append the user message
messages = history + [{"role":"user","content":user_message}]
# pick the right LLM
llm = claude_llm
full = ""
# stream tokens as they arrive
for token in llm.stream(user_message):
full += token
# yield an updated history snapshot
yield messages + [{"role":"assistant","content": full}]
# final history
messages.append({"role":"assistant","content":full})
yield messages
with gr.Blocks(css_paths=["static/deval.css"],theme = gr.themes.Default(primary_hue="blue", secondary_hue="yellow"),) as demo:
# ── Logo + Header + Logout ────────────────────────────────
gr.Image(
value="static/logo.png",
show_label=False,
interactive=False,
show_download_button=False,
show_fullscreen_button=False,
elem_id="logo-primary", # matches the CSS above
)
#logout_btn = gr.Button("Logout", elem_id="logout-btn")
# inject auto-reload script
gr.HTML(
"""
<script>
// Reload the page after 1 minutes (300 000 ms)
setTimeout(() => {
window.location.reload();
}, 1000);
</script>
"""
)
gr.ChatInterface(
chat,
type="messages",
editable=True,
concurrency_limit=200,
save_history=True,
)
demo.queue() \
.launch(auth=AUTHS)