Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,11 +32,21 @@ def call_llm(messages, model="deepseek/deepseek-chat-v3-0324:free", max_tokens=3
|
|
| 32 |
"max_tokens": max_tokens,
|
| 33 |
"temperature": temperature
|
| 34 |
}
|
|
|
|
| 35 |
response = requests.post(url, headers=headers, json=data)
|
| 36 |
-
|
| 37 |
if response.status_code != 200:
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
def get_sources(topic, domains=None):
|
| 42 |
query = topic
|
|
@@ -125,6 +135,10 @@ def generate_download_button(file, label, mime_type):
|
|
| 125 |
</a>
|
| 126 |
"""
|
| 127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
# --- Streamlit UI ---
|
| 129 |
st.set_page_config("Deep Research Bot", layout="wide")
|
| 130 |
|
|
@@ -143,7 +157,7 @@ with st.sidebar:
|
|
| 143 |
])
|
| 144 |
source_type = st.selectbox("π Sources to include", ["Web Only", "Academic Only", "Hybrid"])
|
| 145 |
custom_domains = st.text_input("π Query Domains (Optional)", placeholder="techcrunch.com, forbes.com")
|
| 146 |
-
research_button = st.button("Research")
|
| 147 |
|
| 148 |
st.title("π Research Output")
|
| 149 |
|
|
@@ -187,12 +201,16 @@ Write the report in academic markdown with paragraphs (use bullet points only wh
|
|
| 187 |
3. Novel Insight
|
| 188 |
4. Application
|
| 189 |
5. Full Academic Writeup if Thorough Report
|
| 190 |
-
|
| 191 |
final_output = call_llm([{"role": "user", "content": prompt}])
|
| 192 |
|
| 193 |
st.markdown(f"### π {report_type}")
|
| 194 |
st.markdown(final_output, unsafe_allow_html=True)
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
st.markdown("### π Citations (APA Format)")
|
| 197 |
for cite in citations:
|
| 198 |
st.markdown(f"- {cite}")
|
|
@@ -213,4 +231,4 @@ Write the report in academic markdown with paragraphs (use bullet points only wh
|
|
| 213 |
st.success("β
No major overlaps found.")
|
| 214 |
|
| 215 |
except Exception as e:
|
| 216 |
-
st.error(f"Error: {e}")
|
|
|
|
| 32 |
"max_tokens": max_tokens,
|
| 33 |
"temperature": temperature
|
| 34 |
}
|
| 35 |
+
|
| 36 |
response = requests.post(url, headers=headers, json=data)
|
| 37 |
+
|
| 38 |
if response.status_code != 200:
|
| 39 |
+
try:
|
| 40 |
+
error_msg = response.json().get("error", {}).get("message", "Unknown error from LLM API.")
|
| 41 |
+
except Exception:
|
| 42 |
+
error_msg = response.text
|
| 43 |
+
raise RuntimeError(f"LLM API error: {error_msg}")
|
| 44 |
+
|
| 45 |
+
try:
|
| 46 |
+
result = response.json()
|
| 47 |
+
return result["choices"][0]["message"]["content"]
|
| 48 |
+
except KeyError:
|
| 49 |
+
raise RuntimeError("LLM API returned unexpected response format. Missing 'choices'.")
|
| 50 |
|
| 51 |
def get_sources(topic, domains=None):
|
| 52 |
query = topic
|
|
|
|
| 135 |
</a>
|
| 136 |
"""
|
| 137 |
|
| 138 |
+
def fetch_related_image(topic):
|
| 139 |
+
search_url = f"https://source.unsplash.com/800x400/?{topic}"
|
| 140 |
+
return search_url
|
| 141 |
+
|
| 142 |
# --- Streamlit UI ---
|
| 143 |
st.set_page_config("Deep Research Bot", layout="wide")
|
| 144 |
|
|
|
|
| 157 |
])
|
| 158 |
source_type = st.selectbox("π Sources to include", ["Web Only", "Academic Only", "Hybrid"])
|
| 159 |
custom_domains = st.text_input("π Query Domains (Optional)", placeholder="techcrunch.com, forbes.com")
|
| 160 |
+
research_button = st.button("π Start Research")
|
| 161 |
|
| 162 |
st.title("π Research Output")
|
| 163 |
|
|
|
|
| 201 |
3. Novel Insight
|
| 202 |
4. Application
|
| 203 |
5. Full Academic Writeup if Thorough Report
|
| 204 |
+
"""
|
| 205 |
final_output = call_llm([{"role": "user", "content": prompt}])
|
| 206 |
|
| 207 |
st.markdown(f"### π {report_type}")
|
| 208 |
st.markdown(final_output, unsafe_allow_html=True)
|
| 209 |
|
| 210 |
+
if report_type == "Thorough Academic Research (~10 min)":
|
| 211 |
+
image_url = fetch_related_image(topic)
|
| 212 |
+
st.image(image_url, caption="Related Image", use_column_width=True)
|
| 213 |
+
|
| 214 |
st.markdown("### π Citations (APA Format)")
|
| 215 |
for cite in citations:
|
| 216 |
st.markdown(f"- {cite}")
|
|
|
|
| 231 |
st.success("β
No major overlaps found.")
|
| 232 |
|
| 233 |
except Exception as e:
|
| 234 |
+
st.error(f"Error: {e}")
|