Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # Global variable to store the text | |
| global_text = "" | |
| def set_text(text): | |
| """Updates the global text variable.""" | |
| global global_text | |
| global_text = text | |
| return text # Echo back the text to confirm update in UI | |
| def get_text(): | |
| """Returns the current global text.""" | |
| return global_text | |
| # UI for setting the text | |
| iface = gr.Interface( | |
| fn=set_text, | |
| inputs=gr.Textbox(label="Set Text"), | |
| outputs="text", | |
| title="Text Setter" | |
| ) | |
| # Second UI for getting the text (using a separate interface) | |
| get_text_iface = gr.Interface( | |
| fn=get_text, | |
| inputs=None, # No inputs needed | |
| outputs="text", | |
| title="Text Getter" | |
| ) | |
| # Create a Gradio app to combine them | |
| demo = gr.TabbedInterface( | |
| [iface, get_text_iface], | |
| tab_names=["Set Text", "Get Text UI"] | |
| ) | |
| if __name__ == '__main__': | |
| demo.launch(share=True) |