Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,8 +3,6 @@ import requests
|
|
| 3 |
import json
|
| 4 |
|
| 5 |
def send_post_request(url, const_smiles, var_smiles, main_cls, minor_cls, delta_value, target_name, num):
|
| 6 |
-
# 构造POST请求的JSON数据
|
| 7 |
-
# url:https://songyou-llm-fastapi.hf.space/generate
|
| 8 |
data = {
|
| 9 |
"constSmiles": const_smiles,
|
| 10 |
"varSmiles": var_smiles,
|
|
@@ -16,39 +14,55 @@ def send_post_request(url, const_smiles, var_smiles, main_cls, minor_cls, delta_
|
|
| 16 |
}
|
| 17 |
|
| 18 |
try:
|
| 19 |
-
# 发送POST请求
|
| 20 |
response = requests.post(url, headers={"Content-Type": "application/json"}, data=json.dumps(data))
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
return response.json()
|
| 27 |
except Exception as e:
|
| 28 |
return {"error": str(e)}
|
| 29 |
|
| 30 |
# Gradio UI
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
-
gr.Markdown("#
|
| 33 |
-
|
| 34 |
-
with gr.
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
demo.launch()
|
|
|
|
| 3 |
import json
|
| 4 |
|
| 5 |
def send_post_request(url, const_smiles, var_smiles, main_cls, minor_cls, delta_value, target_name, num):
|
|
|
|
|
|
|
| 6 |
data = {
|
| 7 |
"constSmiles": const_smiles,
|
| 8 |
"varSmiles": var_smiles,
|
|
|
|
| 14 |
}
|
| 15 |
|
| 16 |
try:
|
|
|
|
| 17 |
response = requests.post(url, headers={"Content-Type": "application/json"}, data=json.dumps(data))
|
| 18 |
+
return response.json()
|
| 19 |
+
except Exception as e:
|
| 20 |
+
return {"error": str(e)}
|
| 21 |
+
|
| 22 |
+
def send_get_request(url, smiles):
|
| 23 |
+
params = {"smiles": smiles}
|
| 24 |
+
try:
|
| 25 |
+
response = requests.get(url, params=params)
|
| 26 |
return response.json()
|
| 27 |
except Exception as e:
|
| 28 |
return {"error": str(e)}
|
| 29 |
|
| 30 |
# Gradio UI
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
+
gr.Markdown("# API Request Sender")
|
| 33 |
+
|
| 34 |
+
with gr.Tab("POST /generate"):
|
| 35 |
+
gr.Markdown("Send a POST request to `/generate` endpoint")
|
| 36 |
+
with gr.Row():
|
| 37 |
+
post_url = gr.Textbox(label="Request URL", value="https://songyou-llm-fastapi.hf.space/generate")
|
| 38 |
+
const_smiles = gr.Textbox(label="Constant SMILES")
|
| 39 |
+
var_smiles = gr.Textbox(label="Variable SMILES")
|
| 40 |
+
main_cls = gr.Textbox(label="Main Class")
|
| 41 |
+
minor_cls = gr.Textbox(label="Minor Class")
|
| 42 |
+
delta_value = gr.Textbox(label="Delta Value")
|
| 43 |
+
target_name = gr.Textbox(label="Target Name")
|
| 44 |
+
num = gr.Number(label="Number", precision=0)
|
| 45 |
+
|
| 46 |
+
post_output = gr.Textbox(label="Response")
|
| 47 |
+
post_submit_btn = gr.Button("Submit POST Request")
|
| 48 |
+
post_submit_btn.click(
|
| 49 |
+
send_post_request,
|
| 50 |
+
inputs=[post_url, const_smiles, var_smiles, main_cls, minor_cls, delta_value, target_name, num],
|
| 51 |
+
outputs=post_output
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
with gr.Tab("GET /fragmentize"):
|
| 55 |
+
gr.Markdown("Send a GET request to `/fragmentize` endpoint")
|
| 56 |
+
with gr.Row():
|
| 57 |
+
get_url = gr.Textbox(label="Request URL", value="https://songyou-llm-fastapi.hf.space/fragmentize")
|
| 58 |
+
smiles_input = gr.Textbox(label="SMILES String")
|
| 59 |
+
|
| 60 |
+
get_output = gr.Textbox(label="Response")
|
| 61 |
+
get_submit_btn = gr.Button("Submit GET Request")
|
| 62 |
+
get_submit_btn.click(
|
| 63 |
+
send_get_request,
|
| 64 |
+
inputs=[get_url, smiles_input],
|
| 65 |
+
outputs=get_output
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
demo.launch()
|