davidgaofc commited on
Commit
0c7d341
1 Parent(s): bdebbca

this works?

Browse files
Files changed (1) hide show
  1. app.py +33 -21
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 generate_text(input_text):
8
- added_lines = []
9
- for line in input_text.split('\n'):
10
- if line.startswith('+') and not line.startswith('+++'):
11
- added_line = line[1:] # Remove the '+' sign
12
- if sum(len(l) + 1 for l in added_lines) + len(added_line) <= 2000:
13
- added_lines.append(added_line)
14
- else:
15
- return "Input too long. Please try again."
16
- break
17
- return '\n'.join(added_lines)
18
-
19
- def analyze_sentiment(input_text):
20
- return input_text
21
-
22
-
23
- # Define the Gradio interface
24
- interface1 = gr.Interface(fn=generate_text, inputs="text", outputs="text")
25
- interface2 = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text")
26
-
27
- tabbed_interface = gr.TabbedInterface([interface1, interface2], ["Text Generation", "Sentiment Analysis", "Echo Text"])
 
 
 
 
 
 
 
 
 
 
 
 
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()