Yoel125 commited on
Commit
9ee4d38
·
verified ·
1 Parent(s): a9ad13c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -11,11 +11,11 @@ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
11
  import spaces # <--- Import the Hugging Face spaces library for Free GPU
12
 
13
  # --- 1. LOAD GENERATIVE AI COMPONENT ---
14
- print("Loading GenAI Component on CPU safely for ZeroGPU startup...")
15
 
16
- # THE FIX: Load the model strictly on CPU at the top level to prevent ZeroGPU startup crashes.
17
- gen_tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
18
- gen_model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
19
 
20
  def generate_sales_pitch(user_query, company_name, sector, theme, description):
21
  # Feeding the company's description to the AI so it knows exactly what it's selling
@@ -26,7 +26,7 @@ def generate_sales_pitch(user_query, company_name, sector, theme, description):
26
  )
27
 
28
  try:
29
- # THE FIX: We securely move the model to the GPU only *inside* the function after startup!
30
  device = "cuda" if torch.cuda.is_available() else "cpu"
31
  gen_model.to(device)
32
  inputs = gen_tokenizer(prompt, return_tensors="pt", max_length=256, truncation=True).to(device)
@@ -145,12 +145,14 @@ def recommend_investment(user_query, selected_sector, top_k=3):
145
 
146
  tier_label = match_labels[rank - 1] if rank <= len(match_labels) else "Match"
147
 
 
148
  output_markdown += f"#### #{rank}. {c_name} (`{ticker}`) — *{sector}*\n\n"
149
  output_markdown += f"**{tier_label}** (Similarity Score: `{score*100:.1f}%`)\n\n"
150
  output_markdown += f"**Industry:** {theme}\n\n"
151
  output_markdown += f"**GenAI Investment Pitch:** *'{pitch}'*\n\n"
152
  output_markdown += f"**Company Overview:** {desc[:200]}...\n\n---\n\n"
153
 
 
154
  yield output_markdown
155
 
156
 
 
11
  import spaces # <--- Import the Hugging Face spaces library for Free GPU
12
 
13
  # --- 1. LOAD GENERATIVE AI COMPONENT ---
14
+ print("Loading GenAI Component (Using 'small' model to prevent Hugging Face startup crash)...")
15
 
16
+ # THE FIX: We switched back to 'flan-t5-small'. It loads instantly and won't get killed by Hugging Face!
17
+ gen_tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small")
18
+ gen_model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small")
19
 
20
  def generate_sales_pitch(user_query, company_name, sector, theme, description):
21
  # Feeding the company's description to the AI so it knows exactly what it's selling
 
26
  )
27
 
28
  try:
29
+ # Move the model to the GPU safely *inside* the function!
30
  device = "cuda" if torch.cuda.is_available() else "cpu"
31
  gen_model.to(device)
32
  inputs = gen_tokenizer(prompt, return_tensors="pt", max_length=256, truncation=True).to(device)
 
145
 
146
  tier_label = match_labels[rank - 1] if rank <= len(match_labels) else "Match"
147
 
148
+ # The Fix: No bullet points, reads like a clean, professional report!
149
  output_markdown += f"#### #{rank}. {c_name} (`{ticker}`) — *{sector}*\n\n"
150
  output_markdown += f"**{tier_label}** (Similarity Score: `{score*100:.1f}%`)\n\n"
151
  output_markdown += f"**Industry:** {theme}\n\n"
152
  output_markdown += f"**GenAI Investment Pitch:** *'{pitch}'*\n\n"
153
  output_markdown += f"**Company Overview:** {desc[:200]}...\n\n---\n\n"
154
 
155
+ # Streams the results instantly!
156
  yield output_markdown
157
 
158