Spaces:
Sleeping
Sleeping
Cryptic
commited on
Commit
·
ce2a837
1
Parent(s):
66cc2a4
Initial commit with Streamlit app and requirements
Browse files- app.py +26 -38
- requirements.txt +1 -3
app.py
CHANGED
|
@@ -1,49 +1,37 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
import torch
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-tiny.en", device=-1)
|
| 8 |
-
|
| 9 |
-
# Load Summary Model optimized for CPU
|
| 10 |
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", device=-1)
|
|
|
|
| 11 |
|
| 12 |
-
# Streamlit
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
if uploaded_file is not None:
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Transcribing the audio
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
num_words = len(lecture_text.split())
|
| 26 |
-
max_length = min(num_words, 1024) # BART model max input length is 1024 tokens
|
| 27 |
-
max_length = int(max_length * 0.75) # Approx token conversion
|
| 28 |
-
|
| 29 |
# Summarization
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
summary[0]["summary_text"] = summary[0]["summary_text"][:last_period_index + 1]
|
| 43 |
-
|
| 44 |
-
# Output summary
|
| 45 |
-
st.write("\n### Summary:\n", summary[0]["summary_text"])
|
| 46 |
-
|
| 47 |
-
else:
|
| 48 |
-
st.warning("Please upload a valid audio file.")
|
| 49 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
+
from io import BytesIO
|
|
|
|
| 4 |
|
| 5 |
+
# Load models optimized for CPU
|
| 6 |
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-tiny.en", device=-1)
|
|
|
|
|
|
|
| 7 |
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", device=-1)
|
| 8 |
+
question_generator = pipeline("text2text-generation", model="google/t5-efficient-tiny", device=-1)
|
| 9 |
|
| 10 |
+
# Streamlit UI
|
| 11 |
+
st.title("Curate AI - Audio Transcription and Summarization")
|
| 12 |
|
| 13 |
+
uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "m4a"])
|
| 14 |
if uploaded_file is not None:
|
| 15 |
+
st.audio(uploaded_file, format='audio/wav')
|
| 16 |
+
|
| 17 |
+
# Convert the uploaded file to a format suitable for the transcription model
|
| 18 |
+
audio_bytes = BytesIO(uploaded_file.read())
|
| 19 |
|
| 20 |
# Transcribing the audio
|
| 21 |
+
st.write("Transcribing the audio...")
|
| 22 |
+
lecture_text = transcriber(audio_bytes)["text"]
|
| 23 |
+
st.write("Transcription: ", lecture_text)
|
| 24 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Summarization
|
| 26 |
+
st.write("Summarizing the transcription...")
|
| 27 |
+
num_words = len(lecture_text.split())
|
| 28 |
+
max_length = min(num_words, 1024) # Max input for BART is 1024 tokens
|
| 29 |
+
summary = summarizer(lecture_text, max_length=1024, min_length=int(max_length * 0.1), truncation=True)
|
| 30 |
+
st.write("Summary: ", summary[0]['summary_text'])
|
| 31 |
+
|
| 32 |
+
# Question Generation
|
| 33 |
+
context = f"Based on the following lecture summary: {summary[0]['summary_text']}, generate some relevant practice questions."
|
| 34 |
+
st.write("Generating questions...")
|
| 35 |
+
questions = question_generator(context, max_new_tokens=50)
|
| 36 |
+
for question in questions:
|
| 37 |
+
st.write(question["generated_text"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,4 +1,2 @@
|
|
| 1 |
-
transformers
|
| 2 |
streamlit
|
| 3 |
-
|
| 4 |
-
torch
|
|
|
|
|
|
|
| 1 |
streamlit
|
| 2 |
+
transformers
|
|
|