mgbam commited on
Commit
dd6b41c
·
verified ·
1 Parent(s): 3768f3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -11
app.py CHANGED
@@ -2,36 +2,48 @@ import gradio as gr
2
  from transformers import pipeline
3
 
4
  # Load a more capable open-source model
5
- # You can use "google/flan-t5-large" or other alternatives depending on available resources
6
  strategy_generator = pipeline("text2text-generation", model="google/flan-t5-large")
7
 
 
 
 
 
 
 
 
 
 
 
 
8
  # Function to generate a business strategy
9
  def generate_strategy(industry, challenge, goals):
10
  prompt = f"""
11
- Generate a detailed and actionable business strategy for a company in the {industry} industry.
12
- - Challenge: {challenge}
13
- - Goals: {goals}
14
- Provide realistic steps and measurable outcomes to address the challenge and achieve the goals.
15
  """
16
  try:
17
- response = strategy_generator(prompt, max_length=300, num_return_sequences=1)
18
- return response[0]['generated_text']
 
19
  except Exception as e:
20
  return f"Error generating strategy: {e}"
21
 
22
  # Function to perform a SWOT analysis
23
  def swot_analysis(strengths, weaknesses, opportunities, threats):
24
  prompt = f"""
25
- Perform a comprehensive SWOT analysis for a company based on the following:
26
  - Strengths: {strengths}
27
  - Weaknesses: {weaknesses}
28
  - Opportunities: {opportunities}
29
  - Threats: {threats}
30
- Provide actionable insights for each category to guide business decision-making.
31
  """
32
  try:
33
- response = strategy_generator(prompt, max_length=300, num_return_sequences=1)
34
- return response[0]['generated_text']
 
35
  except Exception as e:
36
  return f"Error generating SWOT analysis: {e}"
37
 
 
2
  from transformers import pipeline
3
 
4
  # Load a more capable open-source model
 
5
  strategy_generator = pipeline("text2text-generation", model="google/flan-t5-large")
6
 
7
+ # Function to clean up repetitive sentences in generated text
8
+ def clean_output(text):
9
+ sentences = text.split(". ")
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 a business consultant helping a company in the {industry} industry.
22
+ The company faces the following challenge: {challenge}.
23
+ The company aims to achieve the following goal: {goals}.
24
+ Provide a detailed and actionable business strategy with specific steps, measurable outcomes, and innovative ideas.
25
  """
26
  try:
27
+ response = strategy_generator(prompt, max_length=300, num_return_sequences=1, temperature=0.7)
28
+ cleaned_response = clean_output(response[0]['generated_text'])
29
+ return cleaned_response
30
  except Exception as e:
31
  return f"Error generating strategy: {e}"
32
 
33
  # Function to perform a SWOT analysis
34
  def swot_analysis(strengths, weaknesses, opportunities, threats):
35
  prompt = f"""
36
+ You are a business consultant performing a SWOT analysis for a company.
37
  - Strengths: {strengths}
38
  - Weaknesses: {weaknesses}
39
  - Opportunities: {opportunities}
40
  - Threats: {threats}
41
+ Provide actionable insights for each category and suggestions on how to maximize strengths and opportunities while addressing weaknesses and threats.
42
  """
43
  try:
44
+ response = strategy_generator(prompt, max_length=300, num_return_sequences=1, temperature=0.7)
45
+ cleaned_response = clean_output(response[0]['generated_text'])
46
+ return cleaned_response
47
  except Exception as e:
48
  return f"Error generating SWOT analysis: {e}"
49