diff --git a/dev_gpt/options/generate/static_files/gateway/app_template.py b/dev_gpt/options/generate/static_files/gateway/app_template.py index a9ec3cd..5da3b26 100644 --- a/dev_gpt/options/generate/static_files/gateway/app_template.py +++ b/dev_gpt/options/generate/static_files/gateway/app_template.py @@ -3,51 +3,68 @@ import os import streamlit as st from jina import Client, Document, DocumentArray -import io -st.set_page_config( - page_title="", - page_icon="", - layout="centered", - initial_sidebar_state="auto", -) - -st.title("
") -st.markdown( - "<10 word description here>" - "To generate and deploy your own microservice, click [here](https://github.com/jina-ai/dev-gpt)." -) -st.subheader(" ") # only if input parameters are needed -with st.form(key="input_form"): - # - input_json_dict = {} # +def main(): + set_page_config() + st.title("
") + st.markdown( + "<10 word description here>" + "To generate and deploy your own microservice, click [here](https://github.com/jina-ai/dev-gpt)." + ) + st.subheader(" ") # only if input parameters are needed + is_submitted, input_json_dict = get_input_parameters() input_json_dict_string = json.dumps(input_json_dict) - submitted = st.form_submit_button("") + # call microservice + if is_submitted: + output_data = make_api_call(input_json_dict_string) + # -# Process input and call microservice -if submitted: + display_curl_command(input_json_dict_string) + +def make_api_call(input_json_dict_string): with st.spinner("..."): client = Client(host="http://localhost:8080") d = Document(text=input_json_dict_string) response = client.post("/", inputs=DocumentArray([d])) output_data = json.loads(response[0].text) - # + return output_data -# Display curl command -deployment_id = os.environ.get("K8S_NAMESPACE_NAME", "") -api_endpoint = ( - f"https://dev-gpt-{deployment_id.split('-')[1]}.wolf.jina.ai/post" - if deployment_id - else "http://localhost:8080/post" -) - -with st.expander("See curl command"): - st.markdown("You can use the following curl command to send a request to the microservice from the command line:") - escaped_input_json_dict_string = input_json_dict_string.replace('"', '\\"') - - st.code( - f'curl -X "POST" "{api_endpoint}" -H "accept: application/json" -H "Content-Type: application/json" -d \'{{"data": [{{"text": "{escaped_input_json_dict_string}"}}]}}\'', - language="bash", +def display_curl_command(input_json_dict_string): + # Display curl command + deployment_id = os.environ.get("K8S_NAMESPACE_NAME", "") + api_endpoint = ( + f"https://dev-gpt-{deployment_id.split('-')[1]}.wolf.jina.ai/post" + if deployment_id + else "http://localhost:8080/post" ) + + with st.expander("See curl command"): + st.markdown( + "You can use the following curl command to send a request to the microservice from the command line:") + escaped_input_json_dict_string = input_json_dict_string.replace('"', '\\"') + + st.code( + f'curl -X "POST" "{api_endpoint}" -H "accept: application/json" -H "Content-Type: application/json" -d \'{{"data": [{{"text": "{escaped_input_json_dict_string}"}}]}}\'', + language="bash", + ) + +def get_input_parameters(): + with st.form(key="input_form"): + # + input_json_dict = {} # + is_submitted = st.form_submit_button("") + return is_submitted, input_json_dict + + +def set_page_config(): + st.set_page_config( + page_title="", + page_icon="", + layout="centered", + initial_sidebar_state="auto", + ) + +if __name__ == "__main__": + main() \ No newline at end of file