Update app.py
Browse files
app.py
CHANGED
@@ -15,47 +15,41 @@ def clean_output(text):
|
|
15 |
cleaned_sentences.append(sentence.strip())
|
16 |
return ". ".join(cleaned_sentences)
|
17 |
|
18 |
-
# Function to validate and refine generated text
|
19 |
-
def validate_output(output, prompt):
|
20 |
-
if len(output.split()) < 10 or output.lower().startswith("the company") or output.count("The company") > 2:
|
21 |
-
return "The response was unclear. Please adjust the input or try again with a refined question."
|
22 |
-
return clean_output(output)
|
23 |
-
|
24 |
# Function to generate a business strategy
|
25 |
def generate_strategy(industry, challenge, goals):
|
26 |
prompt = f"""
|
27 |
-
You are
|
28 |
The company faces the following challenge: {challenge}.
|
29 |
The company's goal is to achieve: {goals}.
|
30 |
-
Provide a strategy
|
31 |
1. Three to five actionable steps.
|
32 |
-
2.
|
33 |
-
Example:
|
34 |
-
1.
|
35 |
-
|
36 |
-
|
37 |
"""
|
38 |
try:
|
39 |
-
response = strategy_generator(prompt, max_length=
|
40 |
-
|
41 |
-
return
|
42 |
except Exception as e:
|
43 |
return f"Error generating strategy: {e}"
|
44 |
|
45 |
# Function to perform a SWOT analysis
|
46 |
def swot_analysis(strengths, weaknesses, opportunities, threats):
|
47 |
prompt = f"""
|
48 |
-
You are
|
49 |
- Strengths: {strengths}
|
50 |
- Weaknesses: {weaknesses}
|
51 |
- Opportunities: {opportunities}
|
52 |
- Threats: {threats}
|
53 |
-
Provide detailed insights for each category and specific recommendations for improvement.
|
54 |
"""
|
55 |
try:
|
56 |
response = strategy_generator(prompt, max_length=300, num_return_sequences=1, temperature=0.7, top_p=0.9)
|
57 |
-
|
58 |
-
return
|
59 |
except Exception as e:
|
60 |
return f"Error generating SWOT analysis: {e}"
|
61 |
|
|
|
15 |
cleaned_sentences.append(sentence.strip())
|
16 |
return ". ".join(cleaned_sentences)
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Function to generate a business strategy
|
19 |
def generate_strategy(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 a detailed strategy that includes:
|
25 |
1. Three to five actionable steps.
|
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=500, num_return_sequences=1, temperature=0.7, top_p=0.9)
|
34 |
+
cleaned_response = clean_output(response[0]['generated_text'])
|
35 |
+
return cleaned_response
|
36 |
except Exception as e:
|
37 |
return f"Error generating strategy: {e}"
|
38 |
|
39 |
# Function to perform a SWOT analysis
|
40 |
def swot_analysis(strengths, weaknesses, opportunities, threats):
|
41 |
prompt = f"""
|
42 |
+
You are a business consultant performing a SWOT analysis for a company.
|
43 |
- Strengths: {strengths}
|
44 |
- Weaknesses: {weaknesses}
|
45 |
- Opportunities: {opportunities}
|
46 |
- Threats: {threats}
|
47 |
+
Provide detailed insights for each category, and include specific recommendations for improvement.
|
48 |
"""
|
49 |
try:
|
50 |
response = strategy_generator(prompt, max_length=300, num_return_sequences=1, temperature=0.7, top_p=0.9)
|
51 |
+
cleaned_response = clean_output(response[0]['generated_text'])
|
52 |
+
return cleaned_response
|
53 |
except Exception as e:
|
54 |
return f"Error generating SWOT analysis: {e}"
|
55 |
|