Spaces:
Sleeping
Sleeping
File size: 6,918 Bytes
0522fe4 4e8a80c 87e5c8c 0522fe4 4e8a80c 7a564aa 4e8a80c 7a564aa 0522fe4 87e5c8c 4e8a80c 87e5c8c 9fb3058 87e5c8c 4e8a80c 77f483c 0250370 0522fe4 4e8a80c 87e5c8c 4e8a80c 87e5c8c 4e8a80c 87e5c8c 4e8a80c 87e5c8c 9fb3058 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c ed43a77 4e8a80c 0522fe4 4e8a80c 9fb3058 4e8a80c | 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | import gradio as gr
import openai
from openai import OpenAI
import os
# Initialize OpenAI client - for Hugging Face Spaces
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
raise ValueError("OPENAI_API_KEY not found in environment variables. Please set it in the Space secrets.")
# Debug: Print first few characters to verify format (remove this after testing)
print(f"API Key format check: {api_key[:10]}...")
client = OpenAI(api_key=api_key)
def generate_business_concept(item1, item2, market1, market2):
"""
Generate a business concept using two items and two target markets
"""
# Validate inputs
if not all([item1, item2, market1, market2]):
return "Please provide all four inputs: two items and two target markets."
# System prompt that defines the GPT's behavior
system_prompt = """1. Generate three distinct business ideas.\n
2. For each idea:\n"
a. Write exactly two sentences describing a business that uses or sells both items as a coherent product or service.\n"
b. Write exactly one sentence describing a hybrid target market that merges the needs and interests of both customer segments.\n"
3. Provide no additional commentary, explanations, or text beyond this.\n"
4. Use the following output format for each idea:\n"
- First two sentences: The business concept\n"
- Third sentence: The hybrid target market"
Provide no additional commentary, explanations, or text beyond this."""
# User message with the inputs
user_message = f"Items: {item1}, {item2}\nTarget Markets: {market1}, {market2}"
try:
# Call OpenAI API
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_message}
],
temperature=0.7,
max_tokens=200
)
return response.choices[0].message.content.strip()
except Exception as e:
return f"Error generating concept: {str(e)}"
# Create Gradio interface with mobile-first design
def create_interface():
with gr.Blocks(
title="Business Concept Generator",
theme=gr.themes.Default(),
css="""
/* Fix viewport and scrolling */
body {
overflow-x: hidden !important;
-webkit-overflow-scrolling: touch !important;
}
/* Main container should be scrollable */
.gradio-container {
max-width: 100% !important;
padding: 10px !important;
min-height: 100vh !important;
overflow-y: auto !important;
overflow-x: hidden !important;
}
/* Ensure the app container is scrollable */
#root, .app {
height: auto !important;
min-height: 100vh !important;
overflow-y: auto !important;
}
/* Compact header */
h1 {
font-size: 20px !important;
margin: 5px 0 10px 0 !important;
line-height: 1.2 !important;
}
/* Make inputs touch-friendly but compact */
input[type="text"], textarea {
font-size: 16px !important; /* Prevents zoom on iOS */
padding: 8px !important;
width: 100% !important;
box-sizing: border-box !important;
}
/* Compact form spacing */
.gr-form {
gap: 5px !important;
}
.gr-textbox {
margin-bottom: 8px !important;
}
/* Smaller labels */
label {
font-size: 14px !important;
margin-bottom: 2px !important;
}
/* Style the button for mobile */
.gr-button {
width: 100% !important;
min-height: 44px !important;
font-size: 16px !important;
font-weight: bold !important;
-webkit-appearance: none !important;
appearance: none !important;
touch-action: manipulation !important;
margin: 10px 0 !important;
position: relative !important;
z-index: 10 !important;
}
/* Output box styling */
#output-box {
margin-top: 10px !important;
margin-bottom: 20px !important;
}
/* Ensure content doesn't get cut off */
.contain {
overflow: visible !important;
}
/* Add padding at bottom for scrolling */
.gradio-container > :last-child {
padding-bottom: 100px !important;
}
/* Force single column on mobile */
@media (max-width: 768px) {
.gr-row {
flex-direction: column !important;
}
.gr-column {
width: 100% !important;
}
}
/* Hide examples on very small screens */
@media (max-width: 375px) {
.gr-accordion {
display: none !important;
}
}
"""
) as demo:
# Add viewport meta tag for proper mobile rendering
gr.HTML("""
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
""")
gr.Markdown("# Business Concept Generator")
# All inputs in a single column
item1 = gr.Textbox(
label="Item 1",
placeholder="First item",
lines=1
)
item2 = gr.Textbox(
label="Item 2",
placeholder="Second item",
lines=1
)
market1 = gr.Textbox(
label="Target Market 1",
placeholder="First market",
lines=1
)
market2 = gr.Textbox(
label="Target Market 2",
placeholder="Second market",
lines=1
)
generate_btn = gr.Button(
"Generate Concept",
variant="primary"
)
output = gr.Textbox(
label="Business Concept",
lines=4,
interactive=False,
elem_id="output-box"
)
# Handle button click
generate_btn.click(
fn=generate_business_concept,
inputs=[item1, item2, market1, market2],
outputs=output,
scroll_to_output=True # This helps scroll to output on mobile
)
# Add some space at the bottom
gr.HTML("<div style='height: 50px;'></div>")
return demo
# Main execution
if __name__ == "__main__":
# Create and launch the interface
demo = create_interface()
demo.launch() |