phuntshowangdi commited on
Commit
ca805e0
1 Parent(s): b6eecda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -41
app.py CHANGED
@@ -1,47 +1,46 @@
1
  import streamlit as st
2
- import spacy
3
-
4
- # Load English language model
5
- nlp = spacy.load("en_core_web_sm")
6
-
7
- def correct_mcq(student_answer, correct_answer):
8
- # Process student's answer and correct answer with Spacy
9
- doc_student = nlp(student_answer)
10
- doc_correct = nlp(correct_answer)
11
-
12
- # Compute similarity between the two answers
13
- similarity_score = doc_student.similarity(doc_correct)
14
-
15
- # Provide feedback based on similarity score
16
- if similarity_score >= 0.8:
17
- feedback = "Correct! Your answer is very similar to the correct answer."
18
- elif similarity_score >= 0.6:
19
- feedback = "Your answer is close, but there are some differences. Review the correct answer."
20
- else:
21
- feedback = "Incorrect. Your answer is quite different from the correct answer. Please review."
22
-
23
- return feedback, similarity_score
24
-
 
 
25
  def main():
26
- st.title("Multiple Choice Questions Correction")
27
-
28
- # Text input for student's answer and correct answer
29
- student_answer = st.text_area("Student's Answer")
30
- correct_answer = st.text_area("Correct Answer")
31
-
32
- if st.button("Check Answer"):
33
- if student_answer and correct_answer:
34
- # Perform correction
35
- feedback, similarity_score = correct_mcq(student_answer, correct_answer)
36
-
37
- # Display feedback and similarity score
38
- st.subheader("Feedback")
39
- st.write(feedback)
40
-
41
- st.subheader("Similarity Score")
42
- st.write(f"{similarity_score:.2f}")
43
  else:
44
- st.warning("Please enter both the student's answer and the correct answer.")
45
 
46
  if __name__ == "__main__":
47
  main()
 
1
  import streamlit as st
2
+ import logging
3
+ from transformers import pipeline
4
+
5
+ # Setup logging
6
+ logging.basicConfig(level=logging.INFO)
7
+
8
+ # Load speech recognition pipeline
9
+ asr = pipeline(task="automatic-speech-recognition",
10
+ model="facebook/wav2vec2-base-960h")
11
+
12
+ # Function for transcribing speech
13
+ def transcribe_speech(audio_file):
14
+ if not audio_file:
15
+ logging.error("No audio file provided.")
16
+ return "No audio found, please retry."
17
+ try:
18
+ logging.info(f"Processing file: {audio_file.name}")
19
+ audio_input = audio_file.read()
20
+ output = asr(audio_input)
21
+ return output[0]['transcription']
22
+ except Exception as e:
23
+ logging.error(f"Error during transcription: {str(e)}")
24
+ return f"Error processing the audio file: {str(e)}"
25
+
26
+ # Streamlit app UI
27
  def main():
28
+ st.title("Simple Speech Recognition App")
29
+ st.write("### This app allows you to record or upload audio and see its transcription.")
30
+
31
+ # Upload audio file or record from microphone
32
+ audio_file = st.file_uploader("Upload Audio File", type=["wav", "mp3"])
33
+ if audio_file:
34
+ st.audio(audio_file, format='audio/wav')
35
+
36
+ # Button to transcribe audio
37
+ if st.button("Transcribe Audio"):
38
+ if audio_file:
39
+ transcription = transcribe_speech(audio_file)
40
+ st.write("### Transcription:")
41
+ st.write(transcription)
 
 
 
42
  else:
43
+ st.warning("Please upload an audio file first.")
44
 
45
  if __name__ == "__main__":
46
  main()