Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| # Set your Hugging Face API key here | |
| API_KEY = "your_huggingface_api_key" | |
| def unified_function(operation, input_text): | |
| if operation == "Text Generation": | |
| return "gen" + input_text | |
| elif operation == "Sentiment Analysis": | |
| return "sent" + input_text | |
| elif operation == "Echo Text": | |
| return "echo" + input_text | |
| def huggingface_login(api_key): | |
| API_KEY = api_key | |
| return "success!" | |
| # Create the Gradio interface | |
| interface = gr.Interface( | |
| fn=unified_function, | |
| inputs=[ | |
| gr.Dropdown(["Text Generation", "Sentiment Analysis", "Echo Text"], label="Select Operation"), | |
| gr.Textbox(label="Input Text") | |
| ], | |
| outputs="text", | |
| title="Unified Interface for Multiple Functions", | |
| description="Select an operation from the dropdown and input text to see the result." | |
| ) | |
| huggingface_interface = gr.Interface( | |
| fn=huggingface_login, | |
| inputs=gr.Textbox(lines=1, label="API Key"), | |
| outputs = "text" | |
| ) | |
| tabbed_interface = gr.TabbedInterface([huggingface_interface, interface], ["Login", "Main"]) | |
| if __name__ == "__main__": | |
| tabbed_interface.launch() |