Spaces:
Sleeping
Sleeping
Download app.py from CuongProjects/Course_query_system: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/CuongProjects/Course_query_system/resolve/main/app.py
- Command line
-
hf download hf://spaces/CuongProjects/Course_query_system/app.py
-
curl -L -o app.py https://huggingface.co/spaces/CuongProjects/Course_query_system/resolve/main/app.py
1.04 kB
| import gradio as gr | |
| from functions_hf import safe_executor, example_queries | |
| def execute_query(query): | |
| result = safe_executor.execute_safe_query(query) | |
| if result['success'] == True: | |
| return result['result'] | |
| else: | |
| return result['error'] | |
| def update_textbox(prompt): | |
| return gr.update(value=prompt) | |
| with gr.Blocks() as demo: | |
| response_box = gr.Textbox(label="Response", interactive=False) | |
| msg = gr.Textbox(label="Type your message or select a prompt") | |
| with gr.Row(): | |
| prompt_dropdown = gr.Dropdown(choices=[""] + example_queries, label="Select a premade prompt", value="") | |
| submit = gr.Button("Submit") | |
| clear = gr.ClearButton([msg, response_box]) | |
| prompt_dropdown.change(update_textbox, inputs=[prompt_dropdown], outputs=[msg]) | |
| submit.click(execute_query, inputs=[msg], outputs=[response_box]) | |
| msg.submit(execute_query, inputs=[msg], outputs=[response_box]) | |
| clear.click(lambda: None, None, [msg, response_box], queue=False) | |
| if __name__ == "__main__": | |
| demo.launch() |