VahidMonfared commited on
Commit
a949d81
·
verified ·
1 Parent(s): 00477ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -16
app.py CHANGED
@@ -41,33 +41,29 @@ def summarize_paragraph(all_texts, section_name, mode="summary"):
41
  unique.append(l)
42
  return " ".join(unique[:4])[:600]
43
 
44
- def get_novel_topic(question, all_texts):
45
- """Generate a unique, new, high-impact topic for research/industry/market based on the user question and current context."""
46
- # Try OpenAI to generate one, fallback to a built-in one
47
  try:
48
  openai_key = os.getenv("OPENAI_API_KEY")
49
  if openai_key:
50
  client = openai.OpenAI(api_key=openai_key)
51
  prompt = (
52
- f"Given this question: {question}\n\n"
53
  f"And these partial answers:\n{chr(10).join(all_texts)}\n\n"
54
- "Propose one specific, novel, valuable, future-oriented research or technology topic that has high potential to advance science, industry, and the market. "
55
- "This idea should be unique, have few existing competitors, and could provide societal and economic benefit if pursued."
56
  )
57
  resp = client.chat.completions.create(
58
  model="gpt-4o",
59
  messages=[{"role": "user", "content": prompt}],
60
  max_tokens=100
61
  )
62
- idea = resp.choices[0].message.content.strip()
63
- # Shorten if too long
64
- return idea[:350]
65
  except Exception:
66
  pass
67
- # Fallback idea—customize as needed!
68
  return (
69
- "Self-healing, AI-optimized materials and manufacturing processes for climate-adaptive infrastructure—"
70
- "enabling bridges, buildings, and devices to sense damage, adapt, and self-repair using intelligent materials and real-time data."
71
  )
72
 
73
  def osint_agent_answer(question):
@@ -162,11 +158,9 @@ def osint_agent_answer(question):
162
  output_lines.append(summarize_paragraph(all_answers, "Best Answer", mode="best"))
163
 
164
  # === RESEARCH AND INDUSTRY GAPS ===
165
- novel_topic = get_novel_topic(question, all_answers)
166
  output_lines.append("=== Research and Industry Gaps ===")
167
- output_lines.append(f"- Science: {novel_topic}")
168
- output_lines.append(f"- Industry: {novel_topic}")
169
- output_lines.append(f"- Market: {novel_topic}")
170
 
171
  if errors:
172
  output_lines.append("\n=== API Errors ===")
 
41
  unique.append(l)
42
  return " ".join(unique[:4])[:600]
43
 
44
+ def get_novel_topic_paragraph(question, all_texts):
45
+ """Return a single concise paragraph about a unique, high-potential topic for research, industry, and market."""
 
46
  try:
47
  openai_key = os.getenv("OPENAI_API_KEY")
48
  if openai_key:
49
  client = openai.OpenAI(api_key=openai_key)
50
  prompt = (
51
+ f"Given this user question: {question}\n\n"
52
  f"And these partial answers:\n{chr(10).join(all_texts)}\n\n"
53
+ "Suggest one new, original, valuable research and technology topic, with a very brief explanation. "
54
+ "This should have strong potential for future science, industry, and the global market. The paragraph should be concise and readable for all audiences."
55
  )
56
  resp = client.chat.completions.create(
57
  model="gpt-4o",
58
  messages=[{"role": "user", "content": prompt}],
59
  max_tokens=100
60
  )
61
+ return resp.choices[0].message.content.strip()
 
 
62
  except Exception:
63
  pass
64
+ # Fallback topic if no LLM is available
65
  return (
66
+ "Adaptive, AI-driven self-repairing materials: Combining smart sensors, machine learning, and advanced manufacturing to create infrastructure and products that can monitor their own condition, detect damage, and trigger self-healing processes—opening vast new possibilities for smart cities, robust devices, and long-term sustainability."
 
67
  )
68
 
69
  def osint_agent_answer(question):
 
158
  output_lines.append(summarize_paragraph(all_answers, "Best Answer", mode="best"))
159
 
160
  # === RESEARCH AND INDUSTRY GAPS ===
161
+ novel_topic = get_novel_topic_paragraph(question, all_answers)
162
  output_lines.append("=== Research and Industry Gaps ===")
163
+ output_lines.append(novel_topic)
 
 
164
 
165
  if errors:
166
  output_lines.append("\n=== API Errors ===")