Spaces:
Paused
Paused
derek-thomas
commited on
Commit
·
91f49a8
1
Parent(s):
5f311b3
Moving endpoint status to backend
Browse files- app.py +1 -24
- backend/query_llm.py +25 -1
app.py
CHANGED
|
@@ -1,14 +1,12 @@
|
|
| 1 |
import logging
|
| 2 |
-
import os
|
| 3 |
from pathlib import Path
|
| 4 |
from time import perf_counter
|
| 5 |
|
| 6 |
import gradio as gr
|
| 7 |
from jinja2 import Environment, FileSystemLoader
|
| 8 |
-
import requests
|
| 9 |
from transformers import AutoTokenizer
|
| 10 |
|
| 11 |
-
from backend.query_llm import generate
|
| 12 |
from backend.semantic_search import retriever
|
| 13 |
|
| 14 |
proj_dir = Path(__file__).parent
|
|
@@ -27,27 +25,6 @@ template_html = env.get_template('template_html.j2')
|
|
| 27 |
tokenizer = AutoTokenizer.from_pretrained('derek-thomas/jais-13b-chat-hf')
|
| 28 |
|
| 29 |
|
| 30 |
-
def check_endpoint_status():
|
| 31 |
-
# Replace with the actual API URL and headers
|
| 32 |
-
api_url = os.getenv("ENDPOINT_URL")
|
| 33 |
-
headers = {
|
| 34 |
-
'accept': 'application/json',
|
| 35 |
-
'Authorization': f'Bearer {os.getenv("BEARER")}'
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
try:
|
| 39 |
-
response = requests.get(api_url, headers=headers)
|
| 40 |
-
response.raise_for_status() # will throw an exception for non-200 status
|
| 41 |
-
data = response.json()
|
| 42 |
-
|
| 43 |
-
# Extracting the status information
|
| 44 |
-
status = data.get('status', {}).get('state', 'No status found')
|
| 45 |
-
message = data.get('status', {}).get('message', 'No message found')
|
| 46 |
-
|
| 47 |
-
return f"Status: {status}\nMessage: {message}"
|
| 48 |
-
except requests.exceptions.RequestException as e:
|
| 49 |
-
return f"Failed to get status: {str(e)}"
|
| 50 |
-
|
| 51 |
def add_text(history, text):
|
| 52 |
history = [] if history is None else history
|
| 53 |
history = history + [(text, None)]
|
|
|
|
| 1 |
import logging
|
|
|
|
| 2 |
from pathlib import Path
|
| 3 |
from time import perf_counter
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
from jinja2 import Environment, FileSystemLoader
|
|
|
|
| 7 |
from transformers import AutoTokenizer
|
| 8 |
|
| 9 |
+
from backend.query_llm import check_endpoint_status, generate
|
| 10 |
from backend.semantic_search import retriever
|
| 11 |
|
| 12 |
proj_dir = Path(__file__).parent
|
|
|
|
| 25 |
tokenizer = AutoTokenizer.from_pretrained('derek-thomas/jais-13b-chat-hf')
|
| 26 |
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
def add_text(history, text):
|
| 29 |
history = [] if history is None else history
|
| 30 |
history = history + [(text, None)]
|
backend/query_llm.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
from os import getenv
|
| 3 |
|
|
@@ -26,4 +28,26 @@ def call_jais(payload):
|
|
| 26 |
def generate(prompt: str):
|
| 27 |
payload = {'inputs': '', 'prompt':prompt}
|
| 28 |
response = call_jais(payload)
|
| 29 |
-
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
import requests
|
| 4 |
from os import getenv
|
| 5 |
|
|
|
|
| 28 |
def generate(prompt: str):
|
| 29 |
payload = {'inputs': '', 'prompt':prompt}
|
| 30 |
response = call_jais(payload)
|
| 31 |
+
return response
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def check_endpoint_status():
|
| 35 |
+
# Replace with the actual API URL and headers
|
| 36 |
+
api_url = os.getenv("ENDPOINT_URL")
|
| 37 |
+
headers = {
|
| 38 |
+
'accept': 'application/json',
|
| 39 |
+
'Authorization': f'Bearer {os.getenv("BEARER")}'
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
response = requests.get(api_url, headers=headers)
|
| 44 |
+
response.raise_for_status() # will throw an exception for non-200 status
|
| 45 |
+
data = response.json()
|
| 46 |
+
|
| 47 |
+
# Extracting the status information
|
| 48 |
+
status = data.get('status', {}).get('state', 'No status found')
|
| 49 |
+
message = data.get('status', {}).get('message', 'No message found')
|
| 50 |
+
|
| 51 |
+
return f"Status: {status}\nMessage: {message}"
|
| 52 |
+
except requests.exceptions.RequestException as e:
|
| 53 |
+
return f"Failed to get status: {str(e)}"
|