davidgaofc's picture
trying
bdebbca
raw
history blame
1.01 kB
import gradio as gr
import requests
# Set your Hugging Face API key here
API_KEY = "your_huggingface_api_key"
def generate_text(input_text):
added_lines = []
for line in input_text.split('\n'):
if line.startswith('+') and not line.startswith('+++'):
added_line = line[1:] # Remove the '+' sign
if sum(len(l) + 1 for l in added_lines) + len(added_line) <= 2000:
added_lines.append(added_line)
else:
return "Input too long. Please try again."
break
return '\n'.join(added_lines)
def analyze_sentiment(input_text):
return input_text
# Define the Gradio interface
interface1 = gr.Interface(fn=generate_text, inputs="text", outputs="text")
interface2 = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text")
tabbed_interface = gr.TabbedInterface([interface1, interface2], ["Text Generation", "Sentiment Analysis", "Echo Text"])
if __name__ == "__main__":
tabbed_interface.launch()