Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -32,16 +32,6 @@ import markdown
|
|
32 |
import PyPDF2
|
33 |
import io
|
34 |
import copy
|
35 |
-
from pathlib import Path
|
36 |
-
|
37 |
-
# Set up static paths for file access
|
38 |
-
STATIC_DIR = Path("static")
|
39 |
-
AUDIO_DIR = STATIC_DIR / "audio"
|
40 |
-
STATIC_DIR.mkdir(exist_ok=True)
|
41 |
-
AUDIO_DIR.mkdir(exist_ok=True)
|
42 |
-
|
43 |
-
# Set static paths for Gradio
|
44 |
-
gr.set_static_paths(paths=[STATIC_DIR.absolute()])
|
45 |
|
46 |
def get_instructor_name(speaker):
|
47 |
instructor_names = {
|
@@ -411,22 +401,6 @@ def create_zip_of_files(file_paths):
|
|
411 |
|
412 |
# Access local files
|
413 |
def get_gradio_file_url(local_path):
|
414 |
-
"""Get the correct file URL for both private and public spaces."""
|
415 |
-
if not local_path:
|
416 |
-
return None
|
417 |
-
|
418 |
-
# If the path is already a URL, return it
|
419 |
-
if local_path.startswith(('http://', 'https://', '/gradio_api/')):
|
420 |
-
return local_path
|
421 |
-
|
422 |
-
# Get the base name of the file
|
423 |
-
file_name = os.path.basename(local_path)
|
424 |
-
|
425 |
-
# For default audio files, use the static path
|
426 |
-
if file_name in ["professor_lectura_male.mp3", "feynman.mp3", "einstein.mp3", "samantha.mp3", "socrates.mp3"]:
|
427 |
-
return f"/gradio_api/file=static/audio/{file_name}"
|
428 |
-
|
429 |
-
# For other files, use the relative path
|
430 |
relative_path = os.path.relpath(local_path, os.getcwd())
|
431 |
return f"/gradio_api/file={relative_path}"
|
432 |
|
@@ -1483,7 +1457,6 @@ async def study_mode_process(file, api_service, api_key):
|
|
1483 |
|
1484 |
# Gradio interface
|
1485 |
with gr.Blocks(
|
1486 |
-
|
1487 |
title="Lectūra AI",
|
1488 |
css="""
|
1489 |
h1 {text-align: center; color: #fff !important;}
|
@@ -2034,11 +2007,7 @@ with gr.Blocks(
|
|
2034 |
|
2035 |
# Handle speaker selection
|
2036 |
def update_speaker_audio(speaker):
|
2037 |
-
"""Update speaker audio with the correct file path."""
|
2038 |
logger.info(f"Speaker selection changed to: {speaker}")
|
2039 |
-
# Use the public space path for default audio files
|
2040 |
-
if speaker in ["professor_lectura_male.mp3", "feynman.mp3", "einstein.mp3", "samantha.mp3", "socrates.mp3"]:
|
2041 |
-
return f"audio_files/{speaker}"
|
2042 |
return speaker
|
2043 |
|
2044 |
speaker_select.change(
|
@@ -2089,8 +2058,6 @@ with gr.Blocks(
|
|
2089 |
observer.observe(document.body, { childList: true, subtree: true });
|
2090 |
"""
|
2091 |
|
2092 |
-
# --- AGENT LOGIC FOR NOTES, STUDY GUIDE, QUIZ, AND CHAT ---
|
2093 |
-
|
2094 |
async def run_note_agent(api_service, api_key, lecture_context, note_title, note_content):
|
2095 |
model_client = get_model_client(api_service, api_key)
|
2096 |
system_message = (
|
@@ -2115,7 +2082,7 @@ with gr.Blocks(
|
|
2115 |
return extracted
|
2116 |
except Exception:
|
2117 |
continue
|
2118 |
-
|
2119 |
for msg in reversed(result.messages):
|
2120 |
if hasattr(msg, 'content') and isinstance(msg.content, str):
|
2121 |
try:
|
@@ -2199,9 +2166,7 @@ with gr.Blocks(
|
|
2199 |
return extracted, None
|
2200 |
return None, msg.content.strip()
|
2201 |
return None, "No response."
|
2202 |
-
|
2203 |
-
# --- UI WIRING FOR NOTES, STUDY GUIDE, QUIZ, AND CHAT ---
|
2204 |
-
|
2205 |
def update_notes_list(notes):
|
2206 |
"""Convert notes list to DataFrame format for Gradio Dataframe (titles only)."""
|
2207 |
return [[n["title"]] for n in notes]
|
@@ -2259,9 +2224,6 @@ with gr.Blocks(
|
|
2259 |
outputs=note_response
|
2260 |
)
|
2261 |
|
2262 |
-
# Make right column scrollable (wrap in a scrollable gr.Column if needed)
|
2263 |
-
# (Assume CSS already allows #right-column to scroll)
|
2264 |
-
|
2265 |
# --- NOTES LOGIC ---
|
2266 |
def note_type_prefix(note_type, title):
|
2267 |
if note_type and not title.startswith(note_type):
|
@@ -2278,6 +2240,4 @@ with gr.Blocks(
|
|
2278 |
demo.css += custom_css
|
2279 |
|
2280 |
if __name__ == "__main__":
|
2281 |
-
demo.launch(
|
2282 |
-
allowed_paths=[OUTPUT_DIR, UPLOAD_DIR, str(STATIC_DIR)]
|
2283 |
-
)
|
|
|
32 |
import PyPDF2
|
33 |
import io
|
34 |
import copy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
def get_instructor_name(speaker):
|
37 |
instructor_names = {
|
|
|
401 |
|
402 |
# Access local files
|
403 |
def get_gradio_file_url(local_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
404 |
relative_path = os.path.relpath(local_path, os.getcwd())
|
405 |
return f"/gradio_api/file={relative_path}"
|
406 |
|
|
|
1457 |
|
1458 |
# Gradio interface
|
1459 |
with gr.Blocks(
|
|
|
1460 |
title="Lectūra AI",
|
1461 |
css="""
|
1462 |
h1 {text-align: center; color: #fff !important;}
|
|
|
2007 |
|
2008 |
# Handle speaker selection
|
2009 |
def update_speaker_audio(speaker):
|
|
|
2010 |
logger.info(f"Speaker selection changed to: {speaker}")
|
|
|
|
|
|
|
2011 |
return speaker
|
2012 |
|
2013 |
speaker_select.change(
|
|
|
2058 |
observer.observe(document.body, { childList: true, subtree: true });
|
2059 |
"""
|
2060 |
|
|
|
|
|
2061 |
async def run_note_agent(api_service, api_key, lecture_context, note_title, note_content):
|
2062 |
model_client = get_model_client(api_service, api_key)
|
2063 |
system_message = (
|
|
|
2082 |
return extracted
|
2083 |
except Exception:
|
2084 |
continue
|
2085 |
+
|
2086 |
for msg in reversed(result.messages):
|
2087 |
if hasattr(msg, 'content') and isinstance(msg.content, str):
|
2088 |
try:
|
|
|
2166 |
return extracted, None
|
2167 |
return None, msg.content.strip()
|
2168 |
return None, "No response."
|
2169 |
+
|
|
|
|
|
2170 |
def update_notes_list(notes):
|
2171 |
"""Convert notes list to DataFrame format for Gradio Dataframe (titles only)."""
|
2172 |
return [[n["title"]] for n in notes]
|
|
|
2224 |
outputs=note_response
|
2225 |
)
|
2226 |
|
|
|
|
|
|
|
2227 |
# --- NOTES LOGIC ---
|
2228 |
def note_type_prefix(note_type, title):
|
2229 |
if note_type and not title.startswith(note_type):
|
|
|
2240 |
demo.css += custom_css
|
2241 |
|
2242 |
if __name__ == "__main__":
|
2243 |
+
demo.launch(allowed_paths=[OUTPUT_DIR])
|
|
|
|