Spaces:
Sleeping
Sleeping
davidgaofc
commited on
Commit
•
0c7d341
1
Parent(s):
bdebbca
this works?
Browse files
app.py
CHANGED
@@ -4,27 +4,39 @@ import requests
|
|
4 |
# Set your Hugging Face API key here
|
5 |
API_KEY = "your_huggingface_api_key"
|
6 |
|
7 |
-
def
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
return
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
if __name__ == "__main__":
|
30 |
tabbed_interface.launch()
|
|
|
4 |
# Set your Hugging Face API key here
|
5 |
API_KEY = "your_huggingface_api_key"
|
6 |
|
7 |
+
def unified_function(operation, input_text):
|
8 |
+
if operation == "Text Generation":
|
9 |
+
return "gen" + input_text
|
10 |
+
|
11 |
+
elif operation == "Sentiment Analysis":
|
12 |
+
|
13 |
+
return "sent" + input_text
|
14 |
+
|
15 |
+
elif operation == "Echo Text":
|
16 |
+
return "echo" + input_text
|
17 |
+
|
18 |
+
def huggingface_login(api_key):
|
19 |
+
API_KEY = api_key
|
20 |
+
return "success!"
|
21 |
+
# Create the Gradio interface
|
22 |
+
interface = gr.Interface(
|
23 |
+
fn=unified_function,
|
24 |
+
inputs=[
|
25 |
+
gr.Dropdown(["Text Generation", "Sentiment Analysis", "Echo Text"], label="Select Operation"),
|
26 |
+
gr.Textbox(label="Input Text")
|
27 |
+
],
|
28 |
+
outputs="text",
|
29 |
+
title="Unified Interface for Multiple Functions",
|
30 |
+
description="Select an operation from the dropdown and input text to see the result."
|
31 |
+
)
|
32 |
+
|
33 |
+
huggingface_interface = gr.Interface(
|
34 |
+
fn=huggingface_login,
|
35 |
+
inputs=gr.Textbox(lines=1, label="API Key"),
|
36 |
+
outputs = "text"
|
37 |
+
)
|
38 |
+
|
39 |
+
tabbed_interface = gr.TabbedInterface([huggingface_interface, interface], ["Login", "Main"])
|
40 |
|
41 |
if __name__ == "__main__":
|
42 |
tabbed_interface.launch()
|