import gradio as gr from transformers import pipeline # Load Hugging Face models # Text generation for keyword suggestions keyword_generator = pipeline("text-generation", model="gpt2", tokenizer="gpt2") # Sentiment analysis for niche review insights sentiment_analyzer = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") # Function to generate keyword suggestions def suggest_keywords(prompt): results = keyword_generator(prompt, max_length=50, num_return_sequences=3) suggestions = [res["text"].strip() for res in results] return "\n".join(suggestions) # Function to analyze sentiment of user-input text def analyze_sentiment(text): sentiments = sentiment_analyzer(text) return sentiments # Gradio Interface Design with gr.Blocks() as app: gr.Markdown( """ # KDP Keyword Suggestion App Generate profitable KDP coloring book niches and analyze customer feedback! """ ) # Section for keyword generation with gr.Row(): with gr.Column(): prompt_input = gr.Textbox( label="Enter Keyword Prompt", placeholder="E.g., coloring book for kids about", ) keyword_output = gr.Textbox(label="Generated Keywords", lines=5) keyword_button = gr.Button("Generate Keywords") keyword_button.click(suggest_keywords, inputs=prompt_input, outputs=keyword_output) # Section for sentiment analysis with gr.Row(): with gr.Column(): review_input = gr.Textbox( label="Enter Text for Sentiment Analysis", placeholder="Paste a customer review or feedback here...", lines=4, ) sentiment_output = gr.Label(label="Sentiment Analysis Result") sentiment_button = gr.Button("Analyze Sentiment") sentiment_button.click(analyze_sentiment, inputs=review_input, outputs=sentiment_output) # Footer gr.Markdown("Built with ❤️ using Hugging Face and Gradio for KDP enthusiasts!") # Launch the app app.launch()