Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
-
|
| 5 |
-
from llama_index import CallbackManager
|
| 6 |
import openai
|
| 7 |
import whisper
|
| 8 |
import uvicorn
|
|
@@ -19,13 +18,6 @@ model = whisper.load_model("large-v3")
|
|
| 19 |
# Set OpenAI API Key
|
| 20 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 21 |
|
| 22 |
-
# Load data
|
| 23 |
-
SimpleDirectoryReader = download_loader('SimpleDirectoryReader')
|
| 24 |
-
reader = SimpleDirectoryReader('./data')
|
| 25 |
-
documents = reader.load_data()
|
| 26 |
-
|
| 27 |
-
# Removed Ollama and Mistral initialization
|
| 28 |
-
|
| 29 |
# Function to transcribe audio
|
| 30 |
def transcribe_audio(audio_file_path):
|
| 31 |
result = model.transcribe(audio_file_path)
|
|
@@ -66,17 +58,23 @@ async def upload_audio(file: UploadFile = File(...)):
|
|
| 66 |
|
| 67 |
return JSONResponse(content={"summary": summary, "lecture_notes": lecture_notes})
|
| 68 |
|
| 69 |
-
# Upload PDF for
|
| 70 |
@app.post("/upload_pdf/")
|
| 71 |
-
async def upload_pdf(
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
# Chat with the LLM for summarized lecture content
|
| 82 |
@app.post("/chat_summary/")
|
|
@@ -91,20 +89,14 @@ async def chat_summary(user_query: BaseModel):
|
|
| 91 |
return response["choices"][0]["message"]["content"]
|
| 92 |
|
| 93 |
# Define Streamlit UI for Hugging Face Spaces
|
| 94 |
-
st.title("AI Summary")
|
| 95 |
|
| 96 |
# Upload Lecture Audio
|
| 97 |
-
st.subheader("Upload
|
| 98 |
-
audio_file = st.file_uploader(".mp4, .mp3
|
| 99 |
-
|
| 100 |
-
# Upload Lecture Link
|
| 101 |
-
st.subheader("or use lecture link")
|
| 102 |
-
lecture_link = st.text_input("URL")
|
| 103 |
|
| 104 |
# Generate button
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
if generate_button:
|
| 108 |
if audio_file:
|
| 109 |
# Save the uploaded audio file
|
| 110 |
file_path = f"./{audio_file.name}"
|
|
@@ -126,10 +118,8 @@ if generate_button:
|
|
| 126 |
|
| 127 |
st.subheader("Generated Lecture Notes")
|
| 128 |
st.text(lecture_notes)
|
| 129 |
-
elif lecture_link:
|
| 130 |
-
st.error("Lecture link feature is not yet implemented.")
|
| 131 |
else:
|
| 132 |
-
st.error("Please upload an audio file
|
| 133 |
|
| 134 |
# Add a chat box for asking questions about the summary
|
| 135 |
st.subheader("Chat with the LLM")
|
|
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
+
|
|
|
|
| 5 |
import openai
|
| 6 |
import whisper
|
| 7 |
import uvicorn
|
|
|
|
| 18 |
# Set OpenAI API Key
|
| 19 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Function to transcribe audio
|
| 22 |
def transcribe_audio(audio_file_path):
|
| 23 |
result = model.transcribe(audio_file_path)
|
|
|
|
| 58 |
|
| 59 |
return JSONResponse(content={"summary": summary, "lecture_notes": lecture_notes})
|
| 60 |
|
| 61 |
+
# Upload PDF for Processing
|
| 62 |
@app.post("/upload_pdf/")
|
| 63 |
+
async def upload_pdf(file: UploadFile = File(...)):
|
| 64 |
+
if file.content_type != 'application/pdf':
|
| 65 |
+
return JSONResponse(status_code=400, content={"error": "File must be a PDF."})
|
| 66 |
+
|
| 67 |
+
if file.spool_max_size > 10 * 1024 * 1024: # 10MB limit
|
| 68 |
+
return JSONResponse(status_code=400, content={"error": "PDF file is too large. Maximum size is 10MB."})
|
| 69 |
+
|
| 70 |
+
file_path = f"./{file.filename}"
|
| 71 |
+
with open(file_path, "wb") as f:
|
| 72 |
+
f.write(await file.read())
|
| 73 |
+
|
| 74 |
+
# Process the PDF (for example, extracting text)
|
| 75 |
+
extracted_text = "PDF processing logic here to extract text from the document."
|
| 76 |
+
|
| 77 |
+
return JSONResponse(content={"status": "PDF processed successfully", "extracted_text": extracted_text})
|
| 78 |
|
| 79 |
# Chat with the LLM for summarized lecture content
|
| 80 |
@app.post("/chat_summary/")
|
|
|
|
| 89 |
return response["choices"][0]["message"]["content"]
|
| 90 |
|
| 91 |
# Define Streamlit UI for Hugging Face Spaces
|
| 92 |
+
st.title("AI Summary Assistant")
|
| 93 |
|
| 94 |
# Upload Lecture Audio
|
| 95 |
+
st.subheader("Upload Lecture Audio")
|
| 96 |
+
audio_file = st.file_uploader("Upload lecture audio (.mp4, .mp3)", type=["mp4", "mp3"])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
# Generate button
|
| 99 |
+
if st.button("Generate Notes"):
|
|
|
|
|
|
|
| 100 |
if audio_file:
|
| 101 |
# Save the uploaded audio file
|
| 102 |
file_path = f"./{audio_file.name}"
|
|
|
|
| 118 |
|
| 119 |
st.subheader("Generated Lecture Notes")
|
| 120 |
st.text(lecture_notes)
|
|
|
|
|
|
|
| 121 |
else:
|
| 122 |
+
st.error("Please upload an audio file.")
|
| 123 |
|
| 124 |
# Add a chat box for asking questions about the summary
|
| 125 |
st.subheader("Chat with the LLM")
|