File size: 3,281 Bytes
1454da9
 
 
 
 
 
c437756
1454da9
 
 
c437756
1454da9
c437756
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1454da9
c437756
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1454da9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import gradio as gr
import requests
import os
from dotenv import load_dotenv
import gradio as gr
import google.generativeai as genai
import json
load_dotenv()
genai.configure(api_key=os.getenv('API_KEY'))
model = genai.GenerativeModel('gemini-1.5-flash') 
PRODUCT_HUNT_BASE_URL = "https://api.producthunt.com/v2/api/graphql"

def fetch_product_hunt_posts(industry, product_type):
    """Fetches the top 10 Product Hunt posts matching the given industry and product type."""

    developer_token = os.getenv("PRODUCT_HUNT_DEVELOPER_TOKEN")

    

    query = """
    query {
      posts(first: 30, order: VOTES) { # Fetch 30 posts
        edges {
          node {
            id
            name
            tagline
            votesCount
            website
            commentsCount
          }
        }
      }
    }
    """

    headers = {"Authorization": f"Bearer {developer_token}"}
    response = requests.post(
        PRODUCT_HUNT_BASE_URL,
        json={"query": query},  
        headers=headers
    )
    response.raise_for_status()

    try:
        data = response.json()
        print(json.dumps(data, indent=2))  

        posts = [edge["node"] for edge in data["data"]["posts"]["edges"]]

        # Filter by industry and product type (case-insensitive)
        filtered_posts = [
            post 
            for post in posts 
            if industry.lower() in post["tagline"].lower() 
            and product_type.lower() in post["tagline"].lower()
        ]

        # Limit to top 3 filtered posts
        top_filtered_posts = filtered_posts[:3]

        return top_filtered_posts 

    except KeyError:
        print("Unexpected API response format.")
        return []
def generate_product_ideas(industry, product_type, target_audience, features, constraints):
  
    product_hunt_posts = fetch_product_hunt_posts(industry, product_type)

    top_products = ", ".join([post["name"] for post in product_hunt_posts[:3]])
    summary = f"Top products in the {industry} {product_type} category include: {top_products}"

    prompt = f"""
    Generate innovative product ideas with these details:

    Industry: {industry}
    Product Type: {product_type}
    Target Audience: {target_audience}
    Desired Features: {features if features else "N/A"}
    Constraints: {constraints if constraints else "N/A"}

    Market Analysis (Product Hunt):
    {summary}

    Provide a concise list of product ideas, each with a brief description.
    """

    response = model.generate_content(prompt)
    return response.text
  
   
    

with gr.Blocks() as interface:
    gr.Markdown("## Product Idea Generator")
    with gr.Row():
        industry = gr.Dropdown(["Technology", "Health", "Finance", "Education", ...], label="Industry")
        product_type = gr.Dropdown(["Hardware", "SaaS", "Mobile App", ...], label="Product Type")
    target_audience = gr.Textbox(label="Target Audience")
    features = gr.Textbox(label="Desired Features")
    constraints = gr.Textbox(label="Constraints")
    submit_button = gr.Button("Generate Ideas")
    output_text = gr.Textbox(label="Product Ideas")

    submit_button.click(generate_product_ideas, inputs=[industry, product_type, target_audience, features, constraints], outputs=output_text)

interface.launch(share=True)