Spaces:
Running
Running
File size: 2,031 Bytes
74885f3 fc203b5 74885f3 6a5126a 74885f3 dfa1e07 fc203b5 74885f3 cdb83f1 74885f3 d4145ba 74885f3 d4145ba 74885f3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import os
import streamlit as st
from audiorecorder import audiorecorder
from apiclient import discovery
from httplib2 import Http
from oauth2client import client, file, tools
from datasets import load_dataset
from huggingface_hub import login
import warnings
from transcription import transcribe
from quiz_generation import generate_quiz_url
SCOPES = "https://www.googleapis.com/auth/forms.body"
def main():
warnings.filterwarnings("ignore")
# Initialize Google Sheets and Forms API services
store = file.Storage("credentials.json")
creds = store.get()
if not creds or creds.invalid:
login(token = os.environ['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'])
dataset = load_dataset("secrets/client_secret_535279977482-vc7fo2d86o7uq3qnl05epg9l6sv6a6s1.apps.googleusercontent.com.json")
flow = client.flow_from_clientsecrets(dataset,SCOPES)
creds = tools.run_flow(flow, store)
form_service = discovery.build("forms", "v1", http=creds.authorize(Http()))
st.title("Quiz Generator")
st.markdown("Record an audio clip and generate a quiz based on the transcribed text.")
audio = audiorecorder("Click to record", "Stop recording")
if len(audio) > 0:
# To play audio in the frontend:
st.audio(audio.tobytes(), format="audio/wav")
# To save audio to a file:
wav_file = open("audio.wav", "wb")
wav_file.write(audio.tobytes())
# Quiz generation section
st.header("Quiz Generation")
if st.button("Generate Quiz"):
with st.spinner("Transcribing audio to generate the quiz..."):
transcribed_text = transcribe("audio.wav")
# Get the explanations for the quiz
quiz_url = generate_quiz_url(transcribed_text, form_service)
st.success("Quiz generated successfully!")
st.text("Quiz Link: " + quiz_url)
st.text("Transcribed Text:\n" + transcribed_text)
if __name__ == '__main__':
main()
|