Spaces:
Build error
Build error
Commit
·
bb9a90d
1
Parent(s):
8ea4cbd
Adding status
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ from time import perf_counter
|
|
4 |
|
5 |
import gradio as gr
|
6 |
from jinja2 import Environment, FileSystemLoader
|
|
|
7 |
|
8 |
from backend.query_llm import generate
|
9 |
from backend.semantic_search import retriever
|
@@ -20,6 +21,26 @@ env = Environment(loader=FileSystemLoader(proj_dir / 'templates'))
|
|
20 |
template = env.get_template('template.j2')
|
21 |
template_html = env.get_template('template_html.j2')
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def add_text(history, text):
|
25 |
history = [] if history is None else history
|
@@ -51,6 +72,7 @@ def bot(history, system_prompt=""):
|
|
51 |
|
52 |
with gr.Blocks() as demo:
|
53 |
with gr.Tab("Application"):
|
|
|
54 |
chatbot = gr.Chatbot(
|
55 |
[],
|
56 |
elem_id="chatbot",
|
|
|
4 |
|
5 |
import gradio as gr
|
6 |
from jinja2 import Environment, FileSystemLoader
|
7 |
+
import requests
|
8 |
|
9 |
from backend.query_llm import generate
|
10 |
from backend.semantic_search import retriever
|
|
|
21 |
template = env.get_template('template.j2')
|
22 |
template_html = env.get_template('template_html.j2')
|
23 |
|
24 |
+
def check_endpoint_status():
|
25 |
+
# Replace with the actual API URL and headers
|
26 |
+
api_url = os.getenv("ENDPOINT_URL")
|
27 |
+
headers = {
|
28 |
+
'accept': 'application/json',
|
29 |
+
'Authorization': f'Bearer {os.getenv("BEARER")}'
|
30 |
+
}
|
31 |
+
|
32 |
+
try:
|
33 |
+
response = requests.get(api_url, headers=headers)
|
34 |
+
response.raise_for_status() # will throw an exception for non-200 status
|
35 |
+
data = response.json()
|
36 |
+
|
37 |
+
# Extracting the status information
|
38 |
+
status = data.get('status', {}).get('state', 'No status found')
|
39 |
+
message = data.get('status', {}).get('message', 'No message found')
|
40 |
+
|
41 |
+
return f"Status: {status}\nMessage: {message}"
|
42 |
+
except requests.exceptions.RequestException as e:
|
43 |
+
return f"Failed to get status: {str(e)}"
|
44 |
|
45 |
def add_text(history, text):
|
46 |
history = [] if history is None else history
|
|
|
72 |
|
73 |
with gr.Blocks() as demo:
|
74 |
with gr.Tab("Application"):
|
75 |
+
output = gr.Textbox(check_endpoint_status, label="Endpoint Status (send chat to wake up)", every=1)
|
76 |
chatbot = gr.Chatbot(
|
77 |
[],
|
78 |
elem_id="chatbot",
|