File size: 2,107 Bytes
a97da81
6e80856
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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()