Update app.py
Browse files
app.py
CHANGED
@@ -15,43 +15,53 @@ def clean_output(text):
|
|
15 |
cleaned_sentences.append(sentence.strip())
|
16 |
return ". ".join(cleaned_sentences)
|
17 |
|
18 |
-
# Function to generate
|
19 |
-
def
|
20 |
prompt = f"""
|
21 |
You are a business consultant with expertise in the {industry} industry.
|
22 |
The company faces the following challenge: {challenge}.
|
23 |
The company's goal is to achieve: {goals}.
|
24 |
-
Provide
|
25 |
-
|
26 |
-
2. For each step, explain WHY it is recommended and HOW to implement it.
|
27 |
-
Example format:
|
28 |
-
1. Actionable Step: Description
|
29 |
-
- Why: Reasoning for this step.
|
30 |
-
- How: Implementation details.
|
31 |
"""
|
32 |
try:
|
33 |
-
response = strategy_generator(prompt, max_length=
|
34 |
cleaned_response = clean_output(response[0]['generated_text'])
|
35 |
return cleaned_response
|
36 |
except Exception as e:
|
37 |
-
return f"Error generating
|
38 |
|
39 |
-
# Function to
|
40 |
-
def
|
41 |
prompt = f"""
|
42 |
-
You are a business consultant
|
43 |
-
|
44 |
-
|
45 |
-
-
|
46 |
-
-
|
47 |
-
Provide detailed insights for each category, and include specific recommendations for improvement.
|
48 |
"""
|
49 |
try:
|
50 |
-
response = strategy_generator(prompt, max_length=
|
51 |
cleaned_response = clean_output(response[0]['generated_text'])
|
52 |
return cleaned_response
|
53 |
except Exception as e:
|
54 |
-
return f"Error
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
# Gradio interface
|
57 |
with gr.Blocks() as demo:
|
@@ -73,21 +83,5 @@ with gr.Blocks() as demo:
|
|
73 |
outputs=[strategy_output]
|
74 |
)
|
75 |
|
76 |
-
# Tab 2: SWOT Analysis
|
77 |
-
with gr.Tab("SWOT Analysis"):
|
78 |
-
gr.Markdown("### Input Information to Perform a SWOT Analysis")
|
79 |
-
strengths_input = gr.Textbox(label="Strengths", placeholder="E.g., Strong brand presence")
|
80 |
-
weaknesses_input = gr.Textbox(label="Weaknesses", placeholder="E.g., Limited market reach")
|
81 |
-
opportunities_input = gr.Textbox(label="Opportunities", placeholder="E.g., Emerging markets")
|
82 |
-
threats_input = gr.Textbox(label="Threats", placeholder="E.g., Rising competition")
|
83 |
-
swot_button = gr.Button("Perform SWOT Analysis")
|
84 |
-
swot_output = gr.Textbox(label="Generated SWOT Analysis", lines=10)
|
85 |
-
|
86 |
-
swot_button.click(
|
87 |
-
swot_analysis,
|
88 |
-
inputs=[strengths_input, weaknesses_input, opportunities_input, threats_input],
|
89 |
-
outputs=[swot_output]
|
90 |
-
)
|
91 |
-
|
92 |
# Launch the Gradio app
|
93 |
demo.launch()
|
|
|
15 |
cleaned_sentences.append(sentence.strip())
|
16 |
return ". ".join(cleaned_sentences)
|
17 |
|
18 |
+
# Function to generate actionable steps
|
19 |
+
def generate_steps(industry, challenge, goals):
|
20 |
prompt = f"""
|
21 |
You are a business consultant with expertise in the {industry} industry.
|
22 |
The company faces the following challenge: {challenge}.
|
23 |
The company's goal is to achieve: {goals}.
|
24 |
+
Provide three to five actionable steps to help the company achieve this goal.
|
25 |
+
Focus on specific, realistic, and innovative strategies relevant to the industry.
|
|
|
|
|
|
|
|
|
|
|
26 |
"""
|
27 |
try:
|
28 |
+
response = strategy_generator(prompt, max_length=300, num_return_sequences=1, temperature=0.7, top_p=0.9)
|
29 |
cleaned_response = clean_output(response[0]['generated_text'])
|
30 |
return cleaned_response
|
31 |
except Exception as e:
|
32 |
+
return f"Error generating steps: {e}"
|
33 |
|
34 |
+
# Function to generate "why" and "how" for each step
|
35 |
+
def expand_step(step):
|
36 |
prompt = f"""
|
37 |
+
You are a business consultant. For the following strategy:
|
38 |
+
"{step}"
|
39 |
+
Provide:
|
40 |
+
- Why this step is recommended.
|
41 |
+
- How to implement this step effectively.
|
|
|
42 |
"""
|
43 |
try:
|
44 |
+
response = strategy_generator(prompt, max_length=200, num_return_sequences=1, temperature=0.7, top_p=0.9)
|
45 |
cleaned_response = clean_output(response[0]['generated_text'])
|
46 |
return cleaned_response
|
47 |
except Exception as e:
|
48 |
+
return f"Error expanding step: {e}"
|
49 |
+
|
50 |
+
# Combined function to generate strategy
|
51 |
+
def generate_strategy(industry, challenge, goals):
|
52 |
+
# Generate initial steps
|
53 |
+
steps = generate_steps(industry, challenge, goals)
|
54 |
+
if "Error" in steps:
|
55 |
+
return steps
|
56 |
+
|
57 |
+
# Expand each step
|
58 |
+
steps_list = steps.split("\n")
|
59 |
+
detailed_steps = []
|
60 |
+
for step in steps_list:
|
61 |
+
if step.strip():
|
62 |
+
detailed_steps.append(f"{step}\n{expand_step(step)}")
|
63 |
+
|
64 |
+
return "\n\n".join(detailed_steps)
|
65 |
|
66 |
# Gradio interface
|
67 |
with gr.Blocks() as demo:
|
|
|
83 |
outputs=[strategy_output]
|
84 |
)
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
# Launch the Gradio app
|
87 |
demo.launch()
|