Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # Original code snippet | |
| # def merge_sort(arr): | |
| # if len(arr) <= 1: | |
| # return arr | |
| # | |
| # mid = len(arr) // 2 | |
| # left = merge_sort(arr[:mid]) | |
| # right = merge_sort(arr[mid:]) | |
| # | |
| # return merge(left, right) | |
| # | |
| # | |
| # def merge(left, right): | |
| # result = [] | |
| # i = j = 0 | |
| # | |
| # while i < len(left) and j < len(right): | |
| # if left[i] <= right[j]: | |
| # result.append(left[i]) | |
| # i += 1 | |
| # else: | |
| # result.append(right[j]) | |
| # j += 1 | |
| # | |
| # result.extend(left[i:]) | |
| # result.extend(right[j:]) | |
| # return result | |
| # | |
| # | |
| # # Example usage | |
| # numbers = [38, 27, 43, 3, 9, 82, 10] | |
| # sorted_numbers = merge_sort(numbers) | |
| # | |
| # print("Original:", numbers) | |
| # print("Sorted:", sorted_numbers) | |
| # Gradio interface | |
| def process_input(input_text): | |
| try: | |
| # Process the input | |
| return f"Processed: {input_text}" | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| # Create the Gradio app | |
| with gr.Blocks(title="Generated Application", theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("# Generated Application") | |
| with gr.Row(): | |
| with gr.Column(): | |
| input_box = gr.Textbox( | |
| label="Input Text", | |
| placeholder="Enter text to process...", | |
| lines=3 | |
| ) | |
| submit_btn = gr.Button("Process", variant="primary") | |
| with gr.Row(): | |
| output_box = gr.Textbox( | |
| label="Output", | |
| interactive=False, | |
| lines=5 | |
| ) | |
| submit_btn.click( | |
| fn=process_input, | |
| inputs=[input_box], | |
| outputs=[output_box] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch(share=False) | |