Spaces:
Sleeping
Sleeping
Merge branch 'v1_feature/interface_beautify' into develop
Browse files- Untitled-1.py +0 -63
- app copy 2.py +0 -63
- app copy.py +0 -20
- app.py +35 -11
Untitled-1.py
DELETED
@@ -1,63 +0,0 @@
|
|
1 |
-
|
2 |
-
import gradio as gr
|
3 |
-
import time
|
4 |
-
|
5 |
-
disease_values = [0.25, 0.5, 0.75]
|
6 |
-
|
7 |
-
def xray_model(diseases, img):
|
8 |
-
return [{disease: disease_values[idx] for idx,disease in enumerate(diseases)}]
|
9 |
-
|
10 |
-
|
11 |
-
def ct_model(diseases, img):
|
12 |
-
return [{disease: 0.1 for disease in diseases}]
|
13 |
-
|
14 |
-
with gr.Blocks() as demo:
|
15 |
-
gr.Markdown(
|
16 |
-
"""
|
17 |
-
# Detect Disease From Scan
|
18 |
-
With this model you can lorem ipsum
|
19 |
-
- ipsum 1
|
20 |
-
- ipsum 2
|
21 |
-
"""
|
22 |
-
)
|
23 |
-
gr.DuplicateButton()
|
24 |
-
disease = gr.CheckboxGroup(
|
25 |
-
info="Select the diseases you want to scan for.",
|
26 |
-
choices=["Covid", "Malaria", "Lung Cancer"], label="Disease to Scan For"
|
27 |
-
)
|
28 |
-
slider = gr.Slider(0, 100)
|
29 |
-
|
30 |
-
with gr.Tab("X-ray") as x_tab:
|
31 |
-
with gr.Row():
|
32 |
-
xray_scan = gr.Image()
|
33 |
-
xray_results = gr.JSON()
|
34 |
-
xray_run = gr.Button("Run")
|
35 |
-
xray_run.click(
|
36 |
-
xray_model,
|
37 |
-
inputs=[disease, xray_scan],
|
38 |
-
outputs=xray_results,
|
39 |
-
api_name="xray_model"
|
40 |
-
)
|
41 |
-
|
42 |
-
with gr.Tab("CT Scan"):
|
43 |
-
with gr.Row():
|
44 |
-
ct_scan = gr.Image()
|
45 |
-
ct_results = gr.JSON()
|
46 |
-
ct_run = gr.Button("Run")
|
47 |
-
ct_run.click(
|
48 |
-
ct_model,
|
49 |
-
inputs=[disease, ct_scan],
|
50 |
-
outputs=ct_results,
|
51 |
-
api_name="ct_model"
|
52 |
-
)
|
53 |
-
|
54 |
-
upload_btn = gr.Button("Upload Results", variant="primary")
|
55 |
-
upload_btn.click(
|
56 |
-
lambda ct, xr: None,
|
57 |
-
inputs=[ct_results, xray_results],
|
58 |
-
outputs=[],
|
59 |
-
)
|
60 |
-
|
61 |
-
if __name__ == "__main__":
|
62 |
-
demo.launch()
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app copy 2.py
DELETED
@@ -1,63 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from gradio_client import Client
|
3 |
-
|
4 |
-
MESAGE_HEADER = """
|
5 |
-
# API Demo (Client component)
|
6 |
-
Welcome to my simple demonstration of the gradio potential as an API.
|
7 |
-
|
8 |
-
It is made of 2 components: *API_demo_server* and *API_demo_client*.
|
9 |
-
|
10 |
-
Server component: [Nuno-Tome/API_demo_server](Nuno-Tome/aPI_demo_server)
|
11 |
-
Client component: [Nuno-Tome/API_demo_client](Nuno-Tome/aPI_demo_client)
|
12 |
-
|
13 |
-
**Just write you message and watch it be returned by the server.**
|
14 |
-
|
15 |
-
"""
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
MESAGE_BMC = """
|
20 |
-
## If you want to support me, you can buy me a coffee:
|
21 |
-
|
22 |
-
[](https://www.buymeacoffee.com/nunotome)
|
23 |
-
"""
|
24 |
-
|
25 |
-
# Print the message header for "By me a coffee" link
|
26 |
-
def print_bmc():
|
27 |
-
|
28 |
-
bmc_link = "https://www.buymeacoffee.com/nuno.tome"
|
29 |
-
image_url = "https://helloimjessa.files.wordpress.com/2021/06/bmc-button.png?w=" # Image URL
|
30 |
-
#image_size = "150px" # Image size
|
31 |
-
#image_link_markdown = f"[]({bmc_link})"
|
32 |
-
image_link_markdown = "[]({bmc_link})"
|
33 |
-
|
34 |
-
gr.Markdown("""
|
35 |
-
[]({bmc_link})
|
36 |
-
""")
|
37 |
-
# Buy me a Coffee Setup
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
client = Client("Nuno-Tome/API_demo_server")
|
44 |
-
DEBUG_MODE = True
|
45 |
-
|
46 |
-
|
47 |
-
def request(text):
|
48 |
-
|
49 |
-
gr.Markdown(
|
50 |
-
"""
|
51 |
-
# Hello World!
|
52 |
-
Start typing below to see the output.
|
53 |
-
""")
|
54 |
-
|
55 |
-
result = client.predict(
|
56 |
-
text,
|
57 |
-
api_name="/predict"
|
58 |
-
)
|
59 |
-
return result
|
60 |
-
|
61 |
-
demo = gr.Interface(fn=request, inputs="textbox", outputs="json")
|
62 |
-
|
63 |
-
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app copy.py
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
from gradio_client import Client
|
2 |
-
import gradio as gr
|
3 |
-
|
4 |
-
DEBUG_MODE = True
|
5 |
-
|
6 |
-
client = Client("Nuno-Tome/API_demo_server")
|
7 |
-
|
8 |
-
def request(text):
|
9 |
-
#if DEBUG_MODE:
|
10 |
-
result = "Hello World"
|
11 |
-
# gr.Markdown("client:" + str(client))
|
12 |
-
# gr.Markdown(f"## Requesting prediction for: {text}")
|
13 |
-
result = client.echo(text, api_name="/echo")
|
14 |
-
#if DEBUG_MODE:
|
15 |
-
# gr.Markdown(f"## Prediction result: {result}")
|
16 |
-
# print(f"Prediction result: {result}")
|
17 |
-
return result
|
18 |
-
|
19 |
-
|
20 |
-
io = gr.Interface(request, "textbox", "json")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -4,11 +4,35 @@ from gradio_client import Client
|
|
4 |
|
5 |
DEBUG_MODE = True
|
6 |
|
|
|
|
|
7 |
|
8 |
-
def update(name):
|
9 |
-
#return f"Welcome to Gradio, {name}!"
|
10 |
-
return {"name": name}
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def send_request(text):
|
13 |
client = Client("Nuno-Tome/API_demo_server")
|
14 |
result = client.predict(
|
@@ -19,18 +43,18 @@ def send_request(text):
|
|
19 |
|
20 |
with gr.Blocks() as demo:
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
25 |
with gr.Row():
|
26 |
with gr.Column():
|
27 |
-
gr.Markdown("Type your message
|
28 |
inp = gr.Textbox(placeholder="What is your name?")
|
29 |
with gr.Column():
|
30 |
-
|
|
|
31 |
btn = gr.Button("Send request to server")
|
32 |
btn.click(fn=send_request, inputs=inp, outputs=out)
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
demo.launch(share=True)
|
|
|
4 |
|
5 |
DEBUG_MODE = True
|
6 |
|
7 |
+
MESAGE_HEADER = """
|
8 |
+
# ππ©π»βπ» API Demo (Client component) ππ©π»βπ»
|
9 |
|
|
|
|
|
|
|
10 |
|
11 |
+
Welcome to my simple demonstration of the gradio potential as an API.
|
12 |
+
|
13 |
+
It is made of 2 components: *API_demo_server* and *API_demo_client*.
|
14 |
+
|
15 |
+
* Server component: ππ [Nuno-Tome/API_demo_server](Nuno-Tome/aPI_demo_server)
|
16 |
+
|
17 |
+
* Client component: ππ©π»βπ» [Nuno-Tome/API_demo_client](Nuno-Tome/aPI_demo_client)
|
18 |
+
|
19 |
+
**Just write you message and watch it be returned by the server.**
|
20 |
+
|
21 |
+
"""
|
22 |
+
|
23 |
+
|
24 |
+
def get_bmc_markdown():
|
25 |
+
bmc_link = "https://www.buymeacoffee.com/nuno.tome"
|
26 |
+
image_url = "https://helloimjessa.files.wordpress.com/2021/06/bmc-button.png" # Image URL
|
27 |
+
image_size = "150" # Image size
|
28 |
+
image_url_full = image_url + "?w=" + image_size
|
29 |
+
image_link_markdown = f"[]({bmc_link})"
|
30 |
+
full_text = """
|
31 |
+
### If you like this project, please consider liking it or buying me a coffee. It will help me to keep working on this and other projects. Thank you!
|
32 |
+
# """ + image_link_markdown
|
33 |
+
return full_text
|
34 |
+
|
35 |
+
|
36 |
def send_request(text):
|
37 |
client = Client("Nuno-Tome/API_demo_server")
|
38 |
result = client.predict(
|
|
|
43 |
|
44 |
with gr.Blocks() as demo:
|
45 |
|
46 |
+
gr.Markdown(MESAGE_HEADER)
|
47 |
+
gr.Markdown(get_bmc_markdown())
|
48 |
+
gr.DuplicateButton()
|
49 |
+
|
50 |
with gr.Row():
|
51 |
with gr.Column():
|
52 |
+
gr.Markdown("**Type your message:**")
|
53 |
inp = gr.Textbox(placeholder="What is your name?")
|
54 |
with gr.Column():
|
55 |
+
gr.Markdown("**This is your gradio api request response:**")
|
56 |
+
out = gr.JSON()
|
57 |
btn = gr.Button("Send request to server")
|
58 |
btn.click(fn=send_request, inputs=inp, outputs=out)
|
59 |
+
|
|
|
|
|
60 |
demo.launch(share=True)
|