jeremierostan commited on
Commit
72de566
·
verified ·
1 Parent(s): 231a90a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -3,10 +3,10 @@ import PyPDF2
3
  import gradio as gr
4
  from groq import Groq
5
 
6
- # Initialize the Groq client
7
  groq_client = Groq(api_key=os.getenv("GROQ_API_KEY"))
8
 
9
- # PDF Extraction Function
10
  def extract_text_from_pdf(pdf_file_path):
11
  with open(pdf_file_path, 'rb') as file:
12
  reader = PyPDF2.PdfReader(file)
@@ -34,7 +34,7 @@ def generate_questions(paper_text):
34
 
35
  return questions
36
 
37
- # Validate each student's answer with the corresponding question and context
38
  def validate_answer(paper_text, question, student_answer):
39
  prompt = (
40
  f"The student was asked questions about a paper they submitted. Compare their answers to the content of the paper."
@@ -49,7 +49,7 @@ def validate_answer(paper_text, question, student_answer):
49
  )
50
  return response.choices[0].message.content
51
 
52
- # Handle PDF upload and question generation
53
  def handle_pdf_upload(pdf_file):
54
  # Save the uploaded file and extract text from it
55
  pdf_file_path = pdf_file.name
@@ -58,10 +58,10 @@ def handle_pdf_upload(pdf_file):
58
  # Generate four types of questions based on the paper's content
59
  questions = generate_questions(paper_text)
60
 
61
- # Return the generated questions for display to the user
62
  return questions
63
 
64
- # Handle answer submission and LLM's final judgment
65
  def handle_answer_submission(pdf_file, student_code, answer1, answer2, answer3, answer4):
66
  # Extract the paper text for validation
67
  pdf_file_path = pdf_file.name
@@ -89,15 +89,15 @@ def handle_answer_submission(pdf_file, student_code, answer1, answer2, answer3,
89
  # Gradio Blocks for the App
90
  with gr.Blocks() as app:
91
  with gr.Row():
92
- # Add an image logo at the top left corner, centered
93
  logo_url = "https://i.ibb.co/S7DCk3K/a-logo-design-with-a-stylized-egyptian-scribe-the-i-L59-Gh-Zn-QASp7v-TUazjdp-A-1-s-Ip-Qq-VRIif-VF5dn.png" # Replace with your actual logo URL
94
  gr.Image(logo_url, label="", show_label=False, height=200)
95
 
96
- # PDF Upload Section
97
  pdf_file = gr.File(label="Upload PDF Paper")
98
  upload_btn = gr.Button("Upload and Generate Questions")
99
 
100
- # Q/A Section with separate inputs for each question
101
  student_code = gr.Textbox(label="Enter your code or initials")
102
  question1 = gr.Textbox(label="Question 1", interactive=False)
103
  answer1 = gr.Textbox(label="Answer to Question 1", placeholder="Your answer here...")
@@ -117,12 +117,12 @@ with gr.Blocks() as app:
117
  # Layout: Upload button right under the file upload, followed by Q/A section
118
  upload_btn.click(fn=handle_pdf_upload, inputs=pdf_file, outputs=[question1, question2, question3, question4])
119
  submit_btn = gr.Button("Submit Answers")
120
- # Now passing answers individually
121
  submit_btn.click(fn=handle_answer_submission, inputs=[pdf_file, student_code, answer1, answer2, answer3, answer4], outputs=output)
122
 
123
- # Add the "Powered by Groq" logo and link at the bottom
124
  with gr.Row():
125
- groq_url = "https://groq.com/wp-content/uploads/2024/03/PBG-mark1-color.svg"
126
  gr.Image(groq_url, label="", show_label=False, height=100)
127
 
128
  # Launch the app
 
3
  import gradio as gr
4
  from groq import Groq
5
 
6
+ # Initialize Groq client
7
  groq_client = Groq(api_key=os.getenv("GROQ_API_KEY"))
8
 
9
+ # Function to extract PDF
10
  def extract_text_from_pdf(pdf_file_path):
11
  with open(pdf_file_path, 'rb') as file:
12
  reader = PyPDF2.PdfReader(file)
 
34
 
35
  return questions
36
 
37
+ # Function to validate each student's answer
38
  def validate_answer(paper_text, question, student_answer):
39
  prompt = (
40
  f"The student was asked questions about a paper they submitted. Compare their answers to the content of the paper."
 
49
  )
50
  return response.choices[0].message.content
51
 
52
+ # Function to handle PDF upload and question generation
53
  def handle_pdf_upload(pdf_file):
54
  # Save the uploaded file and extract text from it
55
  pdf_file_path = pdf_file.name
 
58
  # Generate four types of questions based on the paper's content
59
  questions = generate_questions(paper_text)
60
 
61
+ # Return the generated questions for display
62
  return questions
63
 
64
+ # Function to handle answer submission and LLM's final judgment
65
  def handle_answer_submission(pdf_file, student_code, answer1, answer2, answer3, answer4):
66
  # Extract the paper text for validation
67
  pdf_file_path = pdf_file.name
 
89
  # Gradio Blocks for the App
90
  with gr.Blocks() as app:
91
  with gr.Row():
92
+ # Add Seshat logo
93
  logo_url = "https://i.ibb.co/S7DCk3K/a-logo-design-with-a-stylized-egyptian-scribe-the-i-L59-Gh-Zn-QASp7v-TUazjdp-A-1-s-Ip-Qq-VRIif-VF5dn.png" # Replace with your actual logo URL
94
  gr.Image(logo_url, label="", show_label=False, height=200)
95
 
96
+ # PDF upload Section
97
  pdf_file = gr.File(label="Upload PDF Paper")
98
  upload_btn = gr.Button("Upload and Generate Questions")
99
 
100
+ # Q/A section with separate inputs for each question
101
  student_code = gr.Textbox(label="Enter your code or initials")
102
  question1 = gr.Textbox(label="Question 1", interactive=False)
103
  answer1 = gr.Textbox(label="Answer to Question 1", placeholder="Your answer here...")
 
117
  # Layout: Upload button right under the file upload, followed by Q/A section
118
  upload_btn.click(fn=handle_pdf_upload, inputs=pdf_file, outputs=[question1, question2, question3, question4])
119
  submit_btn = gr.Button("Submit Answers")
120
+ # Passing answers individually
121
  submit_btn.click(fn=handle_answer_submission, inputs=[pdf_file, student_code, answer1, answer2, answer3, answer4], outputs=output)
122
 
123
+ # "Powered by Groq" badge
124
  with gr.Row():
125
+ groq_url = "https://i.ibb.co/FxPsxKF/PBG-mark1-color.png"
126
  gr.Image(groq_url, label="", show_label=False, height=100)
127
 
128
  # Launch the app