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, explain_quiz_answers 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: flow = client.flow_from_clientsecrets( r"C:\Users\Admin\Downloads\client_secret_535279977482-ttq1qb18v1crma5bkf70015qk9e9r2vv.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") transcribed_text = " can you please generate a quiz of 4 questions about ML, each of them with 4 answers and indicate the correct answer" # Get the explanations for the quiz quiz_url, explanations = 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) # Display the explanations st.header("Quiz Explanations") for i, explanation in enumerate(explanations): st.subheader(f"Question {i+1}") st.text(explanation) if __name__ == '__main__': main()