Gianpaolo Macario
commited on
Commit
·
7262a5b
1
Parent(s):
f273191
feat(app): refactor UI with tabs, adding Image Generation
Browse files
app.py
CHANGED
@@ -69,30 +69,72 @@ def calculate(n1, op, n2):
|
|
69 |
if op == "/" and n2 != 0: return str(n1 / n2)
|
70 |
return "Error"
|
71 |
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
with gr.Blocks() as demo:
|
74 |
-
name = gr.Textbox(label="Type your name", placeholder="Enter your name here")
|
75 |
-
greet_btn = gr.Button("Greet")
|
76 |
-
output = gr.Textbox(label="Message")
|
77 |
-
greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
|
78 |
-
joke_btn = gr.Button("Get Dad Joke")
|
79 |
-
joke_output = gr.Textbox(label="Dad Joke")
|
80 |
-
joke_btn.click(fn=get_dad_joke, outputs=joke_output, api_name="get_dad_joke")
|
81 |
-
|
82 |
-
with gr.Row():
|
83 |
-
num1 = gr.Number(label="First Number")
|
84 |
-
operation = gr.Dropdown(
|
85 |
-
choices=["+", "-", "*", "/"],
|
86 |
-
label="Operation"
|
87 |
-
)
|
88 |
-
num2 = gr.Number(label="Second Number")
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
demo.launch(mcp_server=True, share=True)
|
|
|
69 |
if op == "/" and n2 != 0: return str(n1 / n2)
|
70 |
return "Error"
|
71 |
|
72 |
+
def generate_image(prompt: str):
|
73 |
+
"""
|
74 |
+
Generates an image based on a text prompt using the Stable Diffusion model.
|
75 |
+
|
76 |
+
Args:
|
77 |
+
prompt (str): The text prompt to generate the image from.
|
78 |
+
|
79 |
+
Returns:
|
80 |
+
str: The URL of the generated image.
|
81 |
+
"""
|
82 |
+
|
83 |
+
# Call the Stable Diffusion API or model here
|
84 |
+
# For demonstration, we'll return a placeholder image URL
|
85 |
+
return "https://avatars.githubusercontent.com/u/75182?v=4"
|
86 |
+
|
87 |
+
|
88 |
with gr.Blocks() as demo:
|
89 |
+
# name = gr.Textbox(label="Type your name", placeholder="Enter your name here")
|
90 |
+
# greet_btn = gr.Button("Greet")
|
91 |
+
# output = gr.Textbox(label="Message")
|
92 |
+
# greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
|
93 |
+
# joke_btn = gr.Button("Get Dad Joke")
|
94 |
+
# joke_output = gr.Textbox(label="Dad Joke")
|
95 |
+
# joke_btn.click(fn=get_dad_joke, outputs=joke_output, api_name="get_dad_joke")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
+
tab_calc = gr.Tab("Calculator")
|
98 |
+
with tab_calc:
|
99 |
+
with gr.Row():
|
100 |
+
num1 = gr.Number(label="First Number")
|
101 |
+
operation = gr.Dropdown(
|
102 |
+
choices=["+", "-", "*", "/"],
|
103 |
+
label="Operation"
|
104 |
+
)
|
105 |
+
num2 = gr.Number(label="Second Number")
|
106 |
+
|
107 |
+
calc_btn = gr.Button("Calculate")
|
108 |
+
calc_output = gr.Text(label="Result")
|
109 |
+
calc_btn.click(
|
110 |
+
fn=calculate,
|
111 |
+
inputs=[num1, operation, num2],
|
112 |
+
outputs=calc_output,
|
113 |
+
api_name="calculate")
|
114 |
+
|
115 |
+
tab_joke = gr.Tab("Dad Joke")
|
116 |
+
with tab_joke:
|
117 |
+
joke_btn = gr.Button("Get Dad Joke")
|
118 |
+
joke_output = gr.Textbox(label="Dad Joke")
|
119 |
+
joke_btn.click(fn=get_dad_joke, outputs=joke_output, api_name="get_dad_joke")
|
120 |
+
|
121 |
+
tab_greet = gr.Tab("Greet")
|
122 |
+
with tab_greet:
|
123 |
+
name = gr.Textbox(label="Type your name", placeholder="Enter your name here")
|
124 |
+
greet_btn = gr.Button("Greet")
|
125 |
+
output = gr.Textbox(label="Message")
|
126 |
+
greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
|
127 |
+
|
128 |
+
# Generate an image
|
129 |
+
tab_image = gr.Tab("Image Generation")
|
130 |
+
with tab_image:
|
131 |
+
img_prompt = gr.Textbox(
|
132 |
+
label="Image Prompt",
|
133 |
+
placeholder="Enter a prompt for the image generation"
|
134 |
+
)
|
135 |
+
img_btn = gr.Button("Generate Image")
|
136 |
+
img_output = gr.Image(label="Sample Image")
|
137 |
+
img_btn.click(fn=generate_image, inputs=img_prompt, outputs=img_output, api_name="generate_image")
|
138 |
+
|
139 |
|
140 |
demo.launch(mcp_server=True, share=True)
|