thomas commited on
Commit ·
b7adcb8
1
Parent(s): 3add6b8
feature(#86): implement debug ui for sendNotification function
Browse files- Brain/src/gradio_debug.py +41 -0
- app.py +11 -0
- requirements.txt +3 -1
Brain/src/gradio_debug.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""gradio implementaion"""
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import requests
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
DEFAULT_UUID = "c40a09075d11940f"
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def gradio_send_notification(uuid: str, query: str):
|
| 10 |
+
url = "http://localhost:7860/sendNotification"
|
| 11 |
+
data = {
|
| 12 |
+
"confs": {
|
| 13 |
+
"openai_key": "",
|
| 14 |
+
"pinecone_key": "",
|
| 15 |
+
"pinecone_env": "",
|
| 16 |
+
"firebase_key": "",
|
| 17 |
+
"settings": {"temperature": 0.6},
|
| 18 |
+
"token": "eSyP3i7ITZuq8hWn2qutTl:APA91bH1FtWkaTSJwuX4WKWAl3Q-ZFyrOw4UtMP4IfwuvNrHOThH7EvEGIhtguilLRyQNlLiXatEN0xntHAc8bbKobSGjge3wxIHlspbIWY_855CzONqaVdl3y3zOmgKZNnuhYi4gwbh",
|
| 19 |
+
"uuid": uuid,
|
| 20 |
+
},
|
| 21 |
+
"message": query,
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
response = requests.post(
|
| 25 |
+
url, data=json.dumps(data), headers={"Content-Type": "application/json"}
|
| 26 |
+
)
|
| 27 |
+
response = response.json()
|
| 28 |
+
return json.dumps(response["result"]), response["status_code"]
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
debug_send_notification = gr.Interface(
|
| 32 |
+
fn=gradio_send_notification,
|
| 33 |
+
inputs=[
|
| 34 |
+
gr.Textbox(
|
| 35 |
+
label="UUID", placeholder="Please input your UUID.", value=DEFAULT_UUID
|
| 36 |
+
),
|
| 37 |
+
gr.Textbox(label="query", placeholder="Please input your prompt."),
|
| 38 |
+
],
|
| 39 |
+
outputs=[gr.Textbox(label="Result"), gr.Number(label="Status Code")],
|
| 40 |
+
allow_flagging="never",
|
| 41 |
+
)
|
app.py
CHANGED
|
@@ -3,10 +3,14 @@ from fastapi import FastAPI
|
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
import uvicorn
|
| 5 |
|
|
|
|
| 6 |
from Brain.src.router.browser_router import construct_blueprint_browser_api
|
| 7 |
from Brain.src.router.train_router import construct_blueprint_train_api
|
| 8 |
|
| 9 |
from Brain.src.router.api import construct_blueprint_api
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
app = FastAPI()
|
| 12 |
# Set up CORS middleware
|
|
@@ -26,6 +30,13 @@ app.include_router(
|
|
| 26 |
|
| 27 |
app.include_router(construct_blueprint_train_api(), prefix="/train", tags=["ai_train"])
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
import uvicorn
|
| 5 |
|
| 6 |
+
from Brain.src.gradio_debug import debug_send_notification
|
| 7 |
from Brain.src.router.browser_router import construct_blueprint_browser_api
|
| 8 |
from Brain.src.router.train_router import construct_blueprint_train_api
|
| 9 |
|
| 10 |
from Brain.src.router.api import construct_blueprint_api
|
| 11 |
+
import gradio as gr
|
| 12 |
+
import random
|
| 13 |
+
import time
|
| 14 |
|
| 15 |
app = FastAPI()
|
| 16 |
# Set up CORS middleware
|
|
|
|
| 30 |
|
| 31 |
app.include_router(construct_blueprint_train_api(), prefix="/train", tags=["ai_train"])
|
| 32 |
|
| 33 |
+
# gradio
|
| 34 |
+
|
| 35 |
+
CUSTOM_PATH = "/gradio"
|
| 36 |
+
|
| 37 |
+
app = gr.mount_gradio_app(
|
| 38 |
+
app, debug_send_notification, path=f"{CUSTOM_PATH}/sendNotification"
|
| 39 |
+
)
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
| 42 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
requirements.txt
CHANGED
|
@@ -72,4 +72,6 @@ user-agents==2.2.0
|
|
| 72 |
faiss-cpu==1.7.4
|
| 73 |
google-search-results==2.4.2
|
| 74 |
tiktoken==0.4.0
|
| 75 |
-
tiktoken==0.4.0
|
|
|
|
|
|
|
|
|
| 72 |
faiss-cpu==1.7.4
|
| 73 |
google-search-results==2.4.2
|
| 74 |
tiktoken==0.4.0
|
| 75 |
+
tiktoken==0.4.0
|
| 76 |
+
gradio-client==0.2.7
|
| 77 |
+
gradio==3.35.2
|