Spaces:
Sleeping
Sleeping
Commit
·
4701079
1
Parent(s):
84e65f7
yeah
Browse files
app.py
CHANGED
|
@@ -5,7 +5,16 @@ import requests
|
|
| 5 |
API_KEY = "your_huggingface_api_key"
|
| 6 |
|
| 7 |
def generate_text(input_text):
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def analyze_sentiment(input_text):
|
| 11 |
return input_text
|
|
@@ -14,25 +23,11 @@ def echo_text(input_text):
|
|
| 14 |
return input_text
|
| 15 |
|
| 16 |
# Define the Gradio interface
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
],
|
| 23 |
-
inputs=[
|
| 24 |
-
gr.Textbox(lines=2, placeholder="Enter text for generation..."),
|
| 25 |
-
gr.Textbox(lines=2, placeholder="Enter text for sentiment analysis..."),
|
| 26 |
-
gr.Textbox(lines=2, placeholder="Enter text to echo...")
|
| 27 |
-
],
|
| 28 |
-
outputs=[
|
| 29 |
-
"text",
|
| 30 |
-
"text",
|
| 31 |
-
"text"
|
| 32 |
-
],
|
| 33 |
-
title="Multiple Hugging Face Models",
|
| 34 |
-
description="Three different functions: Text generation, Sentiment Analysis, and Echo."
|
| 35 |
-
)
|
| 36 |
|
| 37 |
if __name__ == "__main__":
|
| 38 |
-
|
|
|
|
| 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
|
|
|
|
| 23 |
return input_text
|
| 24 |
|
| 25 |
# Define the Gradio interface
|
| 26 |
+
interface1 = gr.Interface(fn=generate_text, inputs="text", outputs="text")
|
| 27 |
+
interface2 = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text")
|
| 28 |
+
interface3 = gr.Interface(fn=echo_text, inputs="text", outputs="text")
|
| 29 |
+
|
| 30 |
+
tabbed_interface = gr.TabbedInterface([interface1, interface2, interface3], ["Text Generation", "Sentiment Analysis", "Echo Text"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
if __name__ == "__main__":
|
| 33 |
+
tabbed_interface.launch()
|