Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- main.py +77 -2
- product_hunt +60 -0
- requirements.txt +84 -0
main.py
CHANGED
@@ -4,14 +4,89 @@ import os
|
|
4 |
from dotenv import load_dotenv
|
5 |
import gradio as gr
|
6 |
import google.generativeai as genai
|
|
|
7 |
load_dotenv()
|
8 |
genai.configure(api_key=os.getenv('API_KEY'))
|
9 |
model = genai.GenerativeModel('gemini-1.5-flash')
|
|
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def generate_product_ideas(industry, product_type, target_audience, features, constraints):
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
response = model.generate_content(prompt)
|
14 |
-
print(response.text)
|
15 |
return response.text
|
16 |
|
17 |
|
|
|
4 |
from dotenv import load_dotenv
|
5 |
import gradio as gr
|
6 |
import google.generativeai as genai
|
7 |
+
import json
|
8 |
load_dotenv()
|
9 |
genai.configure(api_key=os.getenv('API_KEY'))
|
10 |
model = genai.GenerativeModel('gemini-1.5-flash')
|
11 |
+
PRODUCT_HUNT_BASE_URL = "https://api.producthunt.com/v2/api/graphql"
|
12 |
|
13 |
+
def fetch_product_hunt_posts(industry, product_type):
|
14 |
+
"""Fetches the top 10 Product Hunt posts matching the given industry and product type."""
|
15 |
+
|
16 |
+
developer_token = os.getenv("PRODUCT_HUNT_DEVELOPER_TOKEN")
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
query = """
|
21 |
+
query {
|
22 |
+
posts(first: 30, order: VOTES) { # Fetch 30 posts
|
23 |
+
edges {
|
24 |
+
node {
|
25 |
+
id
|
26 |
+
name
|
27 |
+
tagline
|
28 |
+
votesCount
|
29 |
+
website
|
30 |
+
commentsCount
|
31 |
+
}
|
32 |
+
}
|
33 |
+
}
|
34 |
+
}
|
35 |
+
"""
|
36 |
+
|
37 |
+
headers = {"Authorization": f"Bearer {developer_token}"}
|
38 |
+
response = requests.post(
|
39 |
+
PRODUCT_HUNT_BASE_URL,
|
40 |
+
json={"query": query},
|
41 |
+
headers=headers
|
42 |
+
)
|
43 |
+
response.raise_for_status()
|
44 |
+
|
45 |
+
try:
|
46 |
+
data = response.json()
|
47 |
+
print(json.dumps(data, indent=2))
|
48 |
+
|
49 |
+
posts = [edge["node"] for edge in data["data"]["posts"]["edges"]]
|
50 |
+
|
51 |
+
# Filter by industry and product type (case-insensitive)
|
52 |
+
filtered_posts = [
|
53 |
+
post
|
54 |
+
for post in posts
|
55 |
+
if industry.lower() in post["tagline"].lower()
|
56 |
+
and product_type.lower() in post["tagline"].lower()
|
57 |
+
]
|
58 |
+
|
59 |
+
# Limit to top 3 filtered posts
|
60 |
+
top_filtered_posts = filtered_posts[:3]
|
61 |
+
|
62 |
+
return top_filtered_posts
|
63 |
+
|
64 |
+
except KeyError:
|
65 |
+
print("Unexpected API response format.")
|
66 |
+
return []
|
67 |
def generate_product_ideas(industry, product_type, target_audience, features, constraints):
|
68 |
+
|
69 |
+
product_hunt_posts = fetch_product_hunt_posts(industry, product_type)
|
70 |
+
|
71 |
+
top_products = ", ".join([post["name"] for post in product_hunt_posts[:3]])
|
72 |
+
summary = f"Top products in the {industry} {product_type} category include: {top_products}"
|
73 |
+
|
74 |
+
prompt = f"""
|
75 |
+
Generate innovative product ideas with these details:
|
76 |
+
|
77 |
+
Industry: {industry}
|
78 |
+
Product Type: {product_type}
|
79 |
+
Target Audience: {target_audience}
|
80 |
+
Desired Features: {features if features else "N/A"}
|
81 |
+
Constraints: {constraints if constraints else "N/A"}
|
82 |
+
|
83 |
+
Market Analysis (Product Hunt):
|
84 |
+
{summary}
|
85 |
+
|
86 |
+
Provide a concise list of product ideas, each with a brief description.
|
87 |
+
"""
|
88 |
+
|
89 |
response = model.generate_content(prompt)
|
|
|
90 |
return response.text
|
91 |
|
92 |
|
product_hunt
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import os
|
3 |
+
import json
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
|
6 |
+
load_dotenv()
|
7 |
+
|
8 |
+
PRODUCT_HUNT_BASE_URL = "https://api.producthunt.com/v2/api/graphql"
|
9 |
+
|
10 |
+
def fetch_product_hunt_posts(industry, product_type):
|
11 |
+
"""Fetches the top 10 Product Hunt posts matching the given industry and product type."""
|
12 |
+
|
13 |
+
developer_token = os.getenv("PRODUCT_HUNT_DEVELOPER_TOKEN")
|
14 |
+
|
15 |
+
# Updated GraphQL Query
|
16 |
+
query = """
|
17 |
+
query {
|
18 |
+
posts(first: 10, order: VOTES) {
|
19 |
+
edges {
|
20 |
+
node {
|
21 |
+
id
|
22 |
+
name
|
23 |
+
tagline
|
24 |
+
votesCount
|
25 |
+
website
|
26 |
+
commentsCount
|
27 |
+
}
|
28 |
+
}
|
29 |
+
}
|
30 |
+
}
|
31 |
+
"""
|
32 |
+
|
33 |
+
# Send GraphQL Request (No filter variable)
|
34 |
+
headers = {"Authorization": f"Bearer {developer_token}"}
|
35 |
+
response = requests.post(
|
36 |
+
PRODUCT_HUNT_BASE_URL,
|
37 |
+
json={"query": query},
|
38 |
+
headers=headers
|
39 |
+
)
|
40 |
+
response.raise_for_status()
|
41 |
+
|
42 |
+
# Process Results
|
43 |
+
try:
|
44 |
+
data = response.json()
|
45 |
+
print(json.dumps(data, indent=2)) # Print raw data for debugging
|
46 |
+
|
47 |
+
posts = [edge["node"] for edge in data["data"]["posts"]["edges"]]
|
48 |
+
return posts
|
49 |
+
except KeyError:
|
50 |
+
print("Unexpected API response format.")
|
51 |
+
return []
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
# Example Usage:
|
56 |
+
if __name__ == "__main__":
|
57 |
+
industry = "tech"
|
58 |
+
product_type = "saas"
|
59 |
+
posts = fetch_product_hunt_posts(industry, product_type)
|
60 |
+
print(json.dumps(posts, indent=2))
|
requirements.txt
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
annotated-types==0.7.0
|
3 |
+
anyio==4.4.0
|
4 |
+
beautifulsoup4==4.12.3
|
5 |
+
cachetools==5.4.0
|
6 |
+
certifi==2024.7.4
|
7 |
+
charset-normalizer==3.3.2
|
8 |
+
click==8.1.7
|
9 |
+
contourpy==1.2.1
|
10 |
+
cycler==0.12.1
|
11 |
+
dnspython==2.6.1
|
12 |
+
email_validator==2.2.0
|
13 |
+
fastapi==0.111.1
|
14 |
+
fastapi-cli==0.0.4
|
15 |
+
ffmpy==0.3.2
|
16 |
+
filelock==3.15.4
|
17 |
+
fonttools==4.53.1
|
18 |
+
fsspec==2024.6.1
|
19 |
+
google==3.0.0
|
20 |
+
google-ai-generativelanguage==0.6.6
|
21 |
+
google-api-core==2.19.1
|
22 |
+
google-api-python-client==2.138.0
|
23 |
+
google-auth==2.32.0
|
24 |
+
google-auth-httplib2==0.2.0
|
25 |
+
google-generativeai==0.7.2
|
26 |
+
googleapis-common-protos==1.63.2
|
27 |
+
gradio==4.39.0
|
28 |
+
gradio_client==1.1.1
|
29 |
+
grpcio==1.65.1
|
30 |
+
grpcio-status==1.62.2
|
31 |
+
h11==0.14.0
|
32 |
+
httpcore==1.0.5
|
33 |
+
httplib2==0.22.0
|
34 |
+
httptools==0.6.1
|
35 |
+
httpx==0.27.0
|
36 |
+
huggingface-hub==0.24.3
|
37 |
+
idna==3.7
|
38 |
+
importlib_resources==6.4.0
|
39 |
+
Jinja2==3.1.4
|
40 |
+
kiwisolver==1.4.5
|
41 |
+
markdown-it-py==3.0.0
|
42 |
+
MarkupSafe==2.1.5
|
43 |
+
matplotlib==3.9.1
|
44 |
+
mdurl==0.1.2
|
45 |
+
numpy==2.0.1
|
46 |
+
orjson==3.10.6
|
47 |
+
packaging==24.1
|
48 |
+
pandas==2.2.2
|
49 |
+
pillow==10.4.0
|
50 |
+
proto-plus==1.24.0
|
51 |
+
protobuf==4.25.4
|
52 |
+
pyasn1==0.6.0
|
53 |
+
pyasn1_modules==0.4.0
|
54 |
+
pydantic==2.8.2
|
55 |
+
pydantic_core==2.20.1
|
56 |
+
pydub==0.25.1
|
57 |
+
Pygments==2.18.0
|
58 |
+
pyparsing==3.1.2
|
59 |
+
python-dateutil==2.9.0.post0
|
60 |
+
python-dotenv==1.0.1
|
61 |
+
python-multipart==0.0.9
|
62 |
+
pytz==2024.1
|
63 |
+
PyYAML==6.0.1
|
64 |
+
requests==2.32.3
|
65 |
+
rich==13.7.1
|
66 |
+
rsa==4.9
|
67 |
+
ruff==0.5.5
|
68 |
+
semantic-version==2.10.0
|
69 |
+
shellingham==1.5.4
|
70 |
+
six==1.16.0
|
71 |
+
sniffio==1.3.1
|
72 |
+
soupsieve==2.5
|
73 |
+
starlette==0.37.2
|
74 |
+
tomlkit==0.12.0
|
75 |
+
tqdm==4.66.4
|
76 |
+
typer==0.12.3
|
77 |
+
typing_extensions==4.12.2
|
78 |
+
tzdata==2024.1
|
79 |
+
uritemplate==4.1.1
|
80 |
+
urllib3==2.2.2
|
81 |
+
uvicorn==0.30.3
|
82 |
+
uvloop==0.19.0
|
83 |
+
watchfiles==0.22.0
|
84 |
+
websockets==11.0.3
|