Spaces:
Sleeping
Sleeping
File size: 1,940 Bytes
74885f3 624999a 74885f3 6a5126a 74885f3 bc0a1f1 74885f3 cdb83f1 bc0a1f1 d4145ba 74885f3 bc0a1f1 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 |
import os
import streamlit as st
from audiorecorder import audiorecorder
from apiclient import discovery
from httplib2 import Http
from oauth2client import client, file, tools
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:
# If the credentials are invalid or not present, initiate the authentication flow
flow = client.flow_from_clientsecrets("client_secret_535279977482-vc7fo2d86o7uq3qnl05epg9l6sv6a6s1.apps.googleusercontent.com.json", 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")
# Generate the quiz URL based on the transcribed text and form service
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()
|