Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import openai
|
| 3 |
from openai import OpenAI
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
# Initialize OpenAI client
|
| 7 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 8 |
if not api_key:
|
| 9 |
-
raise ValueError("OPENAI_API_KEY not found in environment variables.
|
| 10 |
-
|
| 11 |
-
# Debug: Print first few characters to verify format (remove this after testing)
|
| 12 |
-
print(f"API Key format check: {api_key[:10]}...")
|
| 13 |
|
| 14 |
client = OpenAI(api_key=api_key)
|
| 15 |
|
| 16 |
def generate_business_concept(item1, item2, market1, market2):
|
| 17 |
-
"""
|
| 18 |
-
Generate a business concept using two items and two target markets
|
| 19 |
-
"""
|
| 20 |
-
# Validate inputs
|
| 21 |
if not all([item1, item2, market1, market2]):
|
| 22 |
return "Please provide all four inputs: two items and two target markets."
|
| 23 |
|
| 24 |
-
# System prompt that defines the GPT's behavior
|
| 25 |
system_prompt = """You are a business concept generator. When given exactly two items and two target markets, you must:
|
| 26 |
|
| 27 |
1. Create exactly two sentences describing a business that uses or sells both items as a coherent product or service.
|
|
@@ -33,11 +24,9 @@ Output format:
|
|
| 33 |
|
| 34 |
Provide no additional commentary, explanations, or text beyond these three sentences."""
|
| 35 |
|
| 36 |
-
# User message with the inputs
|
| 37 |
user_message = f"Items: {item1}, {item2}\nTarget Markets: {market1}, {market2}"
|
| 38 |
|
| 39 |
try:
|
| 40 |
-
# Call OpenAI API
|
| 41 |
response = client.chat.completions.create(
|
| 42 |
model="gpt-3.5-turbo",
|
| 43 |
messages=[
|
|
@@ -47,113 +36,28 @@ Provide no additional commentary, explanations, or text beyond these three sente
|
|
| 47 |
temperature=0.7,
|
| 48 |
max_tokens=200
|
| 49 |
)
|
| 50 |
-
|
| 51 |
return response.choices[0].message.content.strip()
|
| 52 |
-
|
| 53 |
except Exception as e:
|
| 54 |
return f"Error generating concept: {str(e)}"
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
touch-action: manipulation !important;
|
| 75 |
-
}
|
| 76 |
-
@media (max-width: 768px) {
|
| 77 |
-
.gradio-container {
|
| 78 |
-
padding: 10px !important;
|
| 79 |
-
}
|
| 80 |
-
.gr-button {
|
| 81 |
-
font-size: 16px !important;
|
| 82 |
-
padding: 12px !important;
|
| 83 |
-
}
|
| 84 |
-
}
|
| 85 |
-
</style>
|
| 86 |
-
""")
|
| 87 |
-
|
| 88 |
-
with gr.Row():
|
| 89 |
-
with gr.Column(scale=1):
|
| 90 |
-
item1 = gr.Textbox(
|
| 91 |
-
label="Item 1",
|
| 92 |
-
placeholder="Enter the first item",
|
| 93 |
-
lines=1
|
| 94 |
-
)
|
| 95 |
-
item2 = gr.Textbox(
|
| 96 |
-
label="Item 2",
|
| 97 |
-
placeholder="Enter the second item",
|
| 98 |
-
lines=1
|
| 99 |
-
)
|
| 100 |
-
|
| 101 |
-
with gr.Column(scale=1):
|
| 102 |
-
market1 = gr.Textbox(
|
| 103 |
-
label="Target Market 1",
|
| 104 |
-
placeholder="Enter the first target market",
|
| 105 |
-
lines=1
|
| 106 |
-
)
|
| 107 |
-
market2 = gr.Textbox(
|
| 108 |
-
label="Target Market 2",
|
| 109 |
-
placeholder="Enter the second target market",
|
| 110 |
-
lines=1
|
| 111 |
-
)
|
| 112 |
-
|
| 113 |
-
with gr.Row():
|
| 114 |
-
generate_btn = gr.Button(
|
| 115 |
-
"Generate Business Concept",
|
| 116 |
-
variant="primary",
|
| 117 |
-
size="lg",
|
| 118 |
-
elem_id="generate-button"
|
| 119 |
-
)
|
| 120 |
-
|
| 121 |
-
with gr.Row():
|
| 122 |
-
output = gr.Textbox(
|
| 123 |
-
label="Business Concept",
|
| 124 |
-
lines=4,
|
| 125 |
-
interactive=False
|
| 126 |
-
)
|
| 127 |
-
|
| 128 |
-
# Handle button click
|
| 129 |
-
generate_btn.click(
|
| 130 |
-
fn=generate_business_concept,
|
| 131 |
-
inputs=[item1, item2, market1, market2],
|
| 132 |
-
outputs=output
|
| 133 |
-
)
|
| 134 |
-
|
| 135 |
-
# Add examples
|
| 136 |
-
gr.Examples(
|
| 137 |
-
examples=[
|
| 138 |
-
["Coffee", "Books", "Students", "Remote Workers"],
|
| 139 |
-
["Bicycles", "Solar Panels", "Urban Commuters", "Eco-conscious Homeowners"],
|
| 140 |
-
["Yoga Mats", "Smart Watches", "Fitness Enthusiasts", "Busy Professionals"]
|
| 141 |
-
],
|
| 142 |
-
inputs=[item1, item2, market1, market2],
|
| 143 |
-
label="Example Inputs"
|
| 144 |
-
)
|
| 145 |
-
|
| 146 |
-
return demo
|
| 147 |
|
| 148 |
-
# Main execution
|
| 149 |
if __name__ == "__main__":
|
| 150 |
-
|
| 151 |
-
# export OPENAI_API_KEY="your-api-key-here"
|
| 152 |
-
|
| 153 |
-
if not os.getenv("OPENAI_API_KEY"):
|
| 154 |
-
print("Warning: OPENAI_API_KEY environment variable not set!")
|
| 155 |
-
print("Set it using: export OPENAI_API_KEY='your-api-key-here'")
|
| 156 |
-
|
| 157 |
-
# Create and launch the interface
|
| 158 |
-
demo = create_interface()
|
| 159 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from openai import OpenAI
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Initialize OpenAI client
|
| 6 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 7 |
if not api_key:
|
| 8 |
+
raise ValueError("OPENAI_API_KEY not found in environment variables.")
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
client = OpenAI(api_key=api_key)
|
| 11 |
|
| 12 |
def generate_business_concept(item1, item2, market1, market2):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
if not all([item1, item2, market1, market2]):
|
| 14 |
return "Please provide all four inputs: two items and two target markets."
|
| 15 |
|
|
|
|
| 16 |
system_prompt = """You are a business concept generator. When given exactly two items and two target markets, you must:
|
| 17 |
|
| 18 |
1. Create exactly two sentences describing a business that uses or sells both items as a coherent product or service.
|
|
|
|
| 24 |
|
| 25 |
Provide no additional commentary, explanations, or text beyond these three sentences."""
|
| 26 |
|
|
|
|
| 27 |
user_message = f"Items: {item1}, {item2}\nTarget Markets: {market1}, {market2}"
|
| 28 |
|
| 29 |
try:
|
|
|
|
| 30 |
response = client.chat.completions.create(
|
| 31 |
model="gpt-3.5-turbo",
|
| 32 |
messages=[
|
|
|
|
| 36 |
temperature=0.7,
|
| 37 |
max_tokens=200
|
| 38 |
)
|
|
|
|
| 39 |
return response.choices[0].message.content.strip()
|
|
|
|
| 40 |
except Exception as e:
|
| 41 |
return f"Error generating concept: {str(e)}"
|
| 42 |
|
| 43 |
+
# Simple interface - better for mobile
|
| 44 |
+
iface = gr.Interface(
|
| 45 |
+
fn=generate_business_concept,
|
| 46 |
+
inputs=[
|
| 47 |
+
gr.Textbox(label="Item 1", placeholder="Enter first item"),
|
| 48 |
+
gr.Textbox(label="Item 2", placeholder="Enter second item"),
|
| 49 |
+
gr.Textbox(label="Target Market 1", placeholder="Enter first market"),
|
| 50 |
+
gr.Textbox(label="Target Market 2", placeholder="Enter second market")
|
| 51 |
+
],
|
| 52 |
+
outputs=gr.Textbox(label="Business Concept", lines=4),
|
| 53 |
+
title="Business Concept Generator",
|
| 54 |
+
description="Generate business concepts by combining two items and two target markets.",
|
| 55 |
+
examples=[
|
| 56 |
+
["Coffee", "Books", "Students", "Remote Workers"],
|
| 57 |
+
["Bicycles", "Solar Panels", "Urban Commuters", "Eco-conscious Homeowners"]
|
| 58 |
+
],
|
| 59 |
+
theme="default"
|
| 60 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
|
|
|
| 62 |
if __name__ == "__main__":
|
| 63 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|