Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import json | |
| def send_post_request(url, const_smiles, var_smiles, main_cls, minor_cls, delta_value, target_name, num): | |
| data = { | |
| "constSmiles": const_smiles, | |
| "varSmiles": var_smiles, | |
| "mainCls": main_cls, | |
| "minorCls": minor_cls, | |
| "deltaValue": delta_value, | |
| "targetName": target_name, | |
| "num": num | |
| } | |
| try: | |
| response = requests.post(url, headers={"Content-Type": "application/json"}, data=json.dumps(data)) | |
| return response.json() | |
| except Exception as e: | |
| return {"error": str(e)} | |
| def send_get_request(url, smiles): | |
| params = {"smiles": smiles} | |
| try: | |
| response = requests.get(url, params=params) | |
| return response.json() | |
| except Exception as e: | |
| return {"error": str(e)} | |
| # Gradio UI | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# API Request Sender") | |
| with gr.Tab("POST /generate"): | |
| gr.Markdown("Send a POST request to `/generate` endpoint") | |
| with gr.Row(): | |
| post_url = gr.Textbox(label="Request URL", value="https://songyou-llm-fastapi.hf.space/generate") | |
| const_smiles = gr.Textbox(label="Constant SMILES") | |
| var_smiles = gr.Textbox(label="Variable SMILES") | |
| main_cls = gr.Textbox(label="Main Class") | |
| minor_cls = gr.Textbox(label="Minor Class") | |
| delta_value = gr.Textbox(label="Delta Value") | |
| target_name = gr.Textbox(label="Target Name") | |
| num = gr.Number(label="Number", precision=0) | |
| post_output = gr.Textbox(label="Response") | |
| post_submit_btn = gr.Button("Submit POST Request") | |
| post_submit_btn.click( | |
| send_post_request, | |
| inputs=[post_url, const_smiles, var_smiles, main_cls, minor_cls, delta_value, target_name, num], | |
| outputs=post_output | |
| ) | |
| with gr.Tab("GET /fragmentize"): | |
| gr.Markdown("Send a GET request to `/fragmentize` endpoint") | |
| with gr.Row(): | |
| get_url = gr.Textbox(label="Request URL", value="https://songyou-llm-fastapi.hf.space/fragmentize") | |
| smiles_input = gr.Textbox(label="SMILES String") | |
| get_output = gr.Textbox(label="Response") | |
| get_submit_btn = gr.Button("Submit GET Request") | |
| get_submit_btn.click( | |
| send_get_request, | |
| inputs=[get_url, smiles_input], | |
| outputs=get_output | |
| ) | |
| demo.launch() | |