From 7b23ee7c9e4be53f0524f0894d956ba2deacee38 Mon Sep 17 00:00:00 2001 From: Mark Chen Date: Tue, 6 Feb 2024 20:11:35 +0800 Subject: [PATCH] Add gradio to requirements.txt and add frontend demo --- requirements.txt | 3 ++- scripts/app_start.sh | 3 +++ src/app/main.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 scripts/app_start.sh create mode 100644 src/app/main.py diff --git a/requirements.txt b/requirements.txt index c758e73..d7a6217 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ python-multipart config PyGithub httpx -pytest \ No newline at end of file +pytest +gradio \ No newline at end of file diff --git a/scripts/app_start.sh b/scripts/app_start.sh new file mode 100644 index 0000000..8db4c7a --- /dev/null +++ b/scripts/app_start.sh @@ -0,0 +1,3 @@ +# Run two commands in the background at the same time +cd ../src +python3 -m uvicorn index.main:app --reload & python3 app/main.py diff --git a/src/app/main.py b/src/app/main.py new file mode 100644 index 0000000..9e118e1 --- /dev/null +++ b/src/app/main.py @@ -0,0 +1,14 @@ +import gradio as gr +import requests + +def echo(message, history): + # Post the message to the server + response = requests.post("http://127.0.0.1:8000/api/chat/gpt3", data={"user_request": message}) + # Return the response + llm_output = response.json()["result"]['content'] + + return llm_output + +demo = gr.ChatInterface(fn=echo, examples=["What is OpenAI?", "What is LLM?"], title="LLM Chatbot") + +demo.launch() \ No newline at end of file