Update app.py
Browse files
app.py
CHANGED
@@ -10,47 +10,52 @@ def clean_output(text):
|
|
10 |
seen = set()
|
11 |
cleaned_sentences = []
|
12 |
for sentence in sentences:
|
13 |
-
if sentence not in seen:
|
14 |
-
seen.add(sentence)
|
15 |
-
cleaned_sentences.append(sentence)
|
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
|
22 |
The company faces the following challenge: {challenge}.
|
23 |
-
The company
|
24 |
-
Provide a
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
3. Step 3: Description
|
32 |
"""
|
33 |
try:
|
34 |
response = strategy_generator(prompt, max_length=300, num_return_sequences=1, temperature=0.7, top_p=0.9)
|
35 |
-
|
36 |
-
return
|
37 |
except Exception as e:
|
38 |
return f"Error generating strategy: {e}"
|
39 |
|
40 |
# Function to perform a SWOT analysis
|
41 |
def swot_analysis(strengths, weaknesses, opportunities, threats):
|
42 |
prompt = f"""
|
43 |
-
You are
|
44 |
- Strengths: {strengths}
|
45 |
- Weaknesses: {weaknesses}
|
46 |
- Opportunities: {opportunities}
|
47 |
- Threats: {threats}
|
48 |
-
Provide
|
49 |
"""
|
50 |
try:
|
51 |
response = strategy_generator(prompt, max_length=300, num_return_sequences=1, temperature=0.7, top_p=0.9)
|
52 |
-
|
53 |
-
return
|
54 |
except Exception as e:
|
55 |
return f"Error generating SWOT analysis: {e}"
|
56 |
|
|
|
10 |
seen = set()
|
11 |
cleaned_sentences = []
|
12 |
for sentence in sentences:
|
13 |
+
if sentence.strip() not in seen:
|
14 |
+
seen.add(sentence.strip())
|
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 an experienced business consultant specializing in the {industry} industry.
|
28 |
The company faces the following challenge: {challenge}.
|
29 |
+
The company's goal is to achieve: {goals}.
|
30 |
+
Provide a strategy with:
|
31 |
+
1. Three to five actionable steps.
|
32 |
+
2. Measurable outcomes within the next 6 months to 1 year.
|
33 |
+
Example:
|
34 |
+
1. Improve marketing through targeted ads.
|
35 |
+
2. Streamline operations for better efficiency.
|
36 |
+
3. Partner with local businesses to reach new customers.
|
|
|
37 |
"""
|
38 |
try:
|
39 |
response = strategy_generator(prompt, max_length=300, num_return_sequences=1, temperature=0.7, top_p=0.9)
|
40 |
+
validated_response = validate_output(response[0]['generated_text'], prompt)
|
41 |
+
return validated_response
|
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 an experienced business consultant performing a SWOT analysis for a company.
|
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 |
+
validated_response = validate_output(response[0]['generated_text'], prompt)
|
58 |
+
return validated_response
|
59 |
except Exception as e:
|
60 |
return f"Error generating SWOT analysis: {e}"
|
61 |
|