Spaces:
Sleeping
Sleeping
Add app.py via Space Creator
Browse files
app.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# Original code snippet
|
| 4 |
+
# def merge_sort(arr):
|
| 5 |
+
# if len(arr) <= 1:
|
| 6 |
+
# return arr
|
| 7 |
+
#
|
| 8 |
+
# mid = len(arr) // 2
|
| 9 |
+
# left = merge_sort(arr[:mid])
|
| 10 |
+
# right = merge_sort(arr[mid:])
|
| 11 |
+
#
|
| 12 |
+
# return merge(left, right)
|
| 13 |
+
#
|
| 14 |
+
#
|
| 15 |
+
# def merge(left, right):
|
| 16 |
+
# result = []
|
| 17 |
+
# i = j = 0
|
| 18 |
+
#
|
| 19 |
+
# while i < len(left) and j < len(right):
|
| 20 |
+
# if left[i] <= right[j]:
|
| 21 |
+
# result.append(left[i])
|
| 22 |
+
# i += 1
|
| 23 |
+
# else:
|
| 24 |
+
# result.append(right[j])
|
| 25 |
+
# j += 1
|
| 26 |
+
#
|
| 27 |
+
# result.extend(left[i:])
|
| 28 |
+
# result.extend(right[j:])
|
| 29 |
+
# return result
|
| 30 |
+
#
|
| 31 |
+
#
|
| 32 |
+
# # Example usage
|
| 33 |
+
# numbers = [38, 27, 43, 3, 9, 82, 10]
|
| 34 |
+
# sorted_numbers = merge_sort(numbers)
|
| 35 |
+
#
|
| 36 |
+
# print("Original:", numbers)
|
| 37 |
+
# print("Sorted:", sorted_numbers)
|
| 38 |
+
|
| 39 |
+
# Gradio interface
|
| 40 |
+
def process_input(input_text):
|
| 41 |
+
try:
|
| 42 |
+
# Process the input
|
| 43 |
+
return f"Processed: {input_text}"
|
| 44 |
+
except Exception as e:
|
| 45 |
+
return f"Error: {str(e)}"
|
| 46 |
+
|
| 47 |
+
# Create the Gradio app
|
| 48 |
+
with gr.Blocks(title="Generated Application", theme=gr.themes.Soft()) as demo:
|
| 49 |
+
gr.Markdown("# Generated Application")
|
| 50 |
+
|
| 51 |
+
with gr.Row():
|
| 52 |
+
with gr.Column():
|
| 53 |
+
input_box = gr.Textbox(
|
| 54 |
+
label="Input Text",
|
| 55 |
+
placeholder="Enter text to process...",
|
| 56 |
+
lines=3
|
| 57 |
+
)
|
| 58 |
+
submit_btn = gr.Button("Process", variant="primary")
|
| 59 |
+
|
| 60 |
+
with gr.Row():
|
| 61 |
+
output_box = gr.Textbox(
|
| 62 |
+
label="Output",
|
| 63 |
+
interactive=False,
|
| 64 |
+
lines=5
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
submit_btn.click(
|
| 68 |
+
fn=process_input,
|
| 69 |
+
inputs=[input_box],
|
| 70 |
+
outputs=[output_box]
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
demo.launch(share=False)
|