Spaces:
Running
Running
Update app.py
Browse files
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
|
| 45 |
-
"""
|
| 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 |
-
"
|
| 55 |
-
"This
|
| 56 |
)
|
| 57 |
resp = client.chat.completions.create(
|
| 58 |
model="gpt-4o",
|
| 59 |
messages=[{"role": "user", "content": prompt}],
|
| 60 |
max_tokens=100
|
| 61 |
)
|
| 62 |
-
|
| 63 |
-
# Shorten if too long
|
| 64 |
-
return idea[:350]
|
| 65 |
except Exception:
|
| 66 |
pass
|
| 67 |
-
# Fallback
|
| 68 |
return (
|
| 69 |
-
"
|
| 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 =
|
| 166 |
output_lines.append("=== Research and Industry Gaps ===")
|
| 167 |
-
output_lines.append(
|
| 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 ===")
|