Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from io import StringIO
|
|
5 |
|
6 |
# Mapping of Gradio components to Toga equivalents
|
7 |
GRADIO_TO_TOGA = {
|
8 |
-
"Textbox": ("toga.TextInput", "style=Pack(
|
9 |
"Image": ("toga.Label", "Placeholder: Image file picker", "Image Upload"),
|
10 |
"Button": ("toga.Button", "on_press=button_handler", "Submit"),
|
11 |
"Markdown": ("toga.Label", "style=Pack(padding=5, font_size=14)", "Markdown Text"),
|
@@ -106,12 +106,13 @@ def generate_toga_code(components, functions):
|
|
106 |
return "\n".join(toga_code)
|
107 |
|
108 |
# Conversion function
|
109 |
-
def convert_gradio_to_toga(file):
|
110 |
-
if not file:
|
111 |
-
return None, "Please upload a Gradio app Python file."
|
112 |
|
113 |
try:
|
114 |
-
|
|
|
115 |
components, functions = parse_gradio_code(code)
|
116 |
|
117 |
if not components and functions and isinstance(functions[0], str):
|
@@ -129,18 +130,19 @@ def convert_gradio_to_toga(file):
|
|
129 |
# Gradio interface
|
130 |
with gr.Blocks(theme=gr.themes.Soft()) as interface:
|
131 |
gr.Markdown("# Gradio to Toga Converter")
|
132 |
-
gr.Markdown("Upload a Gradio app (.py) to convert
|
133 |
file_input = gr.File(label="Upload Gradio App", file_types=[".py"])
|
|
|
134 |
convert_button = gr.Button("Convert to Toga")
|
135 |
output = gr.File(label="Download Toga App")
|
136 |
status = gr.Textbox(label="Status", interactive=False)
|
137 |
|
138 |
convert_button.click(
|
139 |
fn=convert_gradio_to_toga,
|
140 |
-
inputs=file_input,
|
141 |
outputs=[output, status]
|
142 |
)
|
143 |
|
144 |
-
# Run Gradio
|
145 |
if __name__ == "__main__":
|
146 |
interface.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)), quiet=True)
|
|
|
5 |
|
6 |
# Mapping of Gradio components to Toga equivalents
|
7 |
GRADIO_TO_TOGA = {
|
8 |
+
"Textbox": ("toga.TextInput", "style=Pack(pading=5)", "Text Input"),
|
9 |
"Image": ("toga.Label", "Placeholder: Image file picker", "Image Upload"),
|
10 |
"Button": ("toga.Button", "on_press=button_handler", "Submit"),
|
11 |
"Markdown": ("toga.Label", "style=Pack(padding=5, font_size=14)", "Markdown Text"),
|
|
|
106 |
return "\n".join(toga_code)
|
107 |
|
108 |
# Conversion function
|
109 |
+
def convert_gradio_to_toga(file, code_text):
|
110 |
+
if not file and not code_text:
|
111 |
+
return None, "Please upload a Gradio app Python file or paste code in the textbox."
|
112 |
|
113 |
try:
|
114 |
+
# Use file if provided, else use text
|
115 |
+
code = file.decode('utf-8') if file else code_text
|
116 |
components, functions = parse_gradio_code(code)
|
117 |
|
118 |
if not components and functions and isinstance(functions[0], str):
|
|
|
130 |
# Gradio interface
|
131 |
with gr.Blocks(theme=gr.themes.Soft()) as interface:
|
132 |
gr.Markdown("# Gradio to Toga Converter")
|
133 |
+
gr.Markdown("Upload a Gradio app (.py) or paste the code below to convert to a Toga desktop app.")
|
134 |
file_input = gr.File(label="Upload Gradio App", file_types=[".py"])
|
135 |
+
code_input = gr.Textbox(label="Paste Gradio Code", lines=10, placeholder="Paste your Gradio Python code here...")
|
136 |
convert_button = gr.Button("Convert to Toga")
|
137 |
output = gr.File(label="Download Toga App")
|
138 |
status = gr.Textbox(label="Status", interactive=False)
|
139 |
|
140 |
convert_button.click(
|
141 |
fn=convert_gradio_to_toga,
|
142 |
+
inputs=[file_input, code_input],
|
143 |
outputs=[output, status]
|
144 |
)
|
145 |
|
146 |
+
# Run Gradio for Hugging Face Spaces
|
147 |
if __name__ == "__main__":
|
148 |
interface.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)), quiet=True)
|