FocusFlow Assistant commited on
Commit Β·
48c1ea6
1
Parent(s): 2847ff4
Add Paste Text feature and restore disabled YouTube UI
Browse files
app.py
CHANGED
|
@@ -1151,7 +1151,7 @@ if not st.session_state.focus_mode:
|
|
| 1151 |
youtube_enabled = st.session_state.get("app_config", {}).get("youtube_enabled", True)
|
| 1152 |
|
| 1153 |
if youtube_enabled:
|
| 1154 |
-
with st.expander("
|
| 1155 |
url_input = st.text_input("URL", placeholder="https://youtube.com/... or any webpage", label_visibility="collapsed")
|
| 1156 |
if st.button("Process URL", use_container_width=True):
|
| 1157 |
if not url_input:
|
|
@@ -1203,20 +1203,84 @@ if not st.session_state.focus_mode:
|
|
| 1203 |
except Exception as e:
|
| 1204 |
st.error(f"Error: {str(e)}")
|
| 1205 |
else:
|
| 1206 |
-
with st.expander("βΆοΈ Add YouTube Video"):
|
| 1207 |
st.info(
|
| 1208 |
-
"β οΈ **YouTube is
|
| 1209 |
-
"HuggingFace Spaces blocks outbound network requests
|
| 1210 |
-
"
|
| 1211 |
-
"
|
| 1212 |
-
"
|
| 1213 |
-
"
|
| 1214 |
-
"
|
| 1215 |
)
|
| 1216 |
-
|
| 1217 |
-
|
| 1218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1219 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1220 |
|
| 1221 |
# --- FOCUS MODE UI ---
|
| 1222 |
if st.session_state.focus_mode:
|
|
|
|
| 1151 |
youtube_enabled = st.session_state.get("app_config", {}).get("youtube_enabled", True)
|
| 1152 |
|
| 1153 |
if youtube_enabled:
|
| 1154 |
+
with st.expander("βΆοΈ Add URL / YouTube"):
|
| 1155 |
url_input = st.text_input("URL", placeholder="https://youtube.com/... or any webpage", label_visibility="collapsed")
|
| 1156 |
if st.button("Process URL", use_container_width=True):
|
| 1157 |
if not url_input:
|
|
|
|
| 1203 |
except Exception as e:
|
| 1204 |
st.error(f"Error: {str(e)}")
|
| 1205 |
else:
|
| 1206 |
+
with st.expander("βΆοΈ Add YouTube Video β Local Only"):
|
| 1207 |
st.info(
|
| 1208 |
+
"β οΈ **YouTube is not available in cloud mode.**\n\n"
|
| 1209 |
+
"HuggingFace Spaces blocks outbound network requests.\n\n"
|
| 1210 |
+
"**To use YouTube sources:**\n"
|
| 1211 |
+
"π» Run FocusFlow locally with Ollama\n\n"
|
| 1212 |
+
"**Right now you can:**\n"
|
| 1213 |
+
"π Upload a PDF of your notes\n"
|
| 1214 |
+
"π Paste text directly below"
|
| 1215 |
)
|
| 1216 |
+
|
| 1217 |
+
# Paste Text Input
|
| 1218 |
+
with st.expander("π Paste Text / Notes"):
|
| 1219 |
+
paste_label = st.text_input(
|
| 1220 |
+
"Source name (optional)",
|
| 1221 |
+
placeholder="e.g. Chapter 3 Notes, Lecture Summary...",
|
| 1222 |
+
key="paste_label_input"
|
| 1223 |
+
)
|
| 1224 |
+
|
| 1225 |
+
paste_text = st.text_area(
|
| 1226 |
+
"Paste your text here",
|
| 1227 |
+
placeholder=(
|
| 1228 |
+
"Paste any text here β lecture notes, "
|
| 1229 |
+
"article content, copied webpage text, "
|
| 1230 |
+
"study notes, anything you want to learn from..."
|
| 1231 |
+
),
|
| 1232 |
+
height=200,
|
| 1233 |
+
key="paste_text_input"
|
| 1234 |
+
)
|
| 1235 |
+
|
| 1236 |
+
word_count = len(paste_text.split()) if paste_text else 0
|
| 1237 |
+
if paste_text:
|
| 1238 |
+
st.caption(f"π {word_count} words")
|
| 1239 |
+
|
| 1240 |
+
col1, col2 = st.columns([2, 1])
|
| 1241 |
+
with col1:
|
| 1242 |
+
process_btn = st.button(
|
| 1243 |
+
"β Add as Source",
|
| 1244 |
+
key="process_paste_btn",
|
| 1245 |
+
disabled=len(paste_text.strip()) < 50,
|
| 1246 |
+
use_container_width=True
|
| 1247 |
)
|
| 1248 |
+
with col2:
|
| 1249 |
+
st.caption("Min 50 chars")
|
| 1250 |
+
|
| 1251 |
+
if process_btn and paste_text.strip():
|
| 1252 |
+
source_name = paste_label.strip() if paste_label.strip() \
|
| 1253 |
+
else f"Pasted Text ({word_count} words)"
|
| 1254 |
+
|
| 1255 |
+
with st.spinner("Processing your text..."):
|
| 1256 |
+
try:
|
| 1257 |
+
# Use API_URL which is the global backend URL configured in app.py
|
| 1258 |
+
response = requests.post(
|
| 1259 |
+
f"{API_URL}/ingest_text",
|
| 1260 |
+
json={
|
| 1261 |
+
"text": paste_text.strip(),
|
| 1262 |
+
"source_name": source_name,
|
| 1263 |
+
"source_type": "paste"
|
| 1264 |
+
},
|
| 1265 |
+
headers=get_headers()
|
| 1266 |
+
)
|
| 1267 |
+
if response.status_code == 200:
|
| 1268 |
+
st.success(f"β
'{source_name}' added successfully!")
|
| 1269 |
+
# Remove keys from session_state instead of setting to "" due to Streamlit unchangeable key rules when bound to a widget
|
| 1270 |
+
if "paste_text_input" in st.session_state:
|
| 1271 |
+
del st.session_state["paste_text_input"]
|
| 1272 |
+
if "paste_label_input" in st.session_state:
|
| 1273 |
+
del st.session_state["paste_label_input"]
|
| 1274 |
+
time.sleep(1)
|
| 1275 |
+
st.rerun()
|
| 1276 |
+
else:
|
| 1277 |
+
error = response.json().get("detail", "Unknown error")
|
| 1278 |
+
st.error(f"β Failed to add text: {error}")
|
| 1279 |
+
except Exception as e:
|
| 1280 |
+
st.error(f"β Error: {str(e)}")
|
| 1281 |
+
|
| 1282 |
+
if len(paste_text.strip()) > 0 and len(paste_text.strip()) < 50:
|
| 1283 |
+
st.warning("β οΈ Please paste at least 50 characters.")
|
| 1284 |
|
| 1285 |
# --- FOCUS MODE UI ---
|
| 1286 |
if st.session_state.focus_mode:
|