EaindraKyaw commited on
Commit
5ecd91c
·
verified ·
1 Parent(s): 13b26b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -29
app.py CHANGED
@@ -83,50 +83,26 @@ def split_questions_answers(question_response):
83
  except IndexError:
84
  return "Error: Unable to parse the response.", ""
85
  def format_questions(questions):
86
- """
87
- Format questions to display with proper alignment and structure, adhering to a word limit per line.
88
- """
89
  lines = questions.split("\n")
90
  formatted = []
91
  current_question = ""
92
 
93
- def split_line_by_word_limit(line, limit):
94
- """
95
- Split a line into multiple lines, each adhering to the specified word limit.
96
- """
97
- words = line.split()
98
- formatted_lines = []
99
- current_line = []
100
-
101
- for word in words:
102
- current_line.append(word)
103
- if len(current_line) >= limit: # If word limit is reached
104
- formatted_lines.append(" ".join(current_line))
105
- current_line = []
106
-
107
- # Add the remaining words to the final line
108
- if current_line:
109
- formatted_lines.append(" ".join(current_line))
110
-
111
- return "\n ".join(formatted_lines) # Add proper indentation for multi-line
112
-
113
  for line in lines:
114
  line = line.strip()
115
  if line.startswith(("1.", "2.", "3.", "4.", "5.")): # New question detected
116
  if current_question: # Add the previous question to the formatted list
117
  formatted.append(current_question.strip())
118
- current_question = f"{split_line_by_word_limit(line, 10)}" # Start a new question block
119
  elif line.startswith(("A.", "B.", "C.", "D.")): # Answer option detected
120
- current_question += f"\n {split_line_by_word_limit(line, 10)}" # Add with proper indentation
121
  elif line: # Any additional text
122
- current_question += f"\n {split_line_by_word_limit(line, 10)}" # Continue the current question
123
 
124
  # Append the last question
125
  if current_question:
126
  formatted.append(current_question.strip())
127
-
128
- return "\n\n".join(formatted) # Add spacing between questions
129
-
130
 
131
  def format_answers(answers):
132
  """Format answers to display with consistent alignment."""
@@ -158,6 +134,7 @@ def generate_questions(context, num_questions, questions_type):
158
  except Exception as e:
159
  return f"Error: {str(e)}", ""
160
 
 
161
  # Define Gradio interface
162
  with gr.Blocks() as demo:
163
  gr.Markdown("# Quiz App - Generate Questions")
@@ -178,3 +155,4 @@ with gr.Blocks() as demo:
178
  # Launch the app
179
  demo.launch()
180
 
 
 
83
  except IndexError:
84
  return "Error: Unable to parse the response.", ""
85
  def format_questions(questions):
86
+ """Format questions to display with proper alignment and structure."""
 
 
87
  lines = questions.split("\n")
88
  formatted = []
89
  current_question = ""
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  for line in lines:
92
  line = line.strip()
93
  if line.startswith(("1.", "2.", "3.", "4.", "5.")): # New question detected
94
  if current_question: # Add the previous question to the formatted list
95
  formatted.append(current_question.strip())
96
+ current_question = f"\n{line}" # Start a new question block
97
  elif line.startswith(("A.", "B.", "C.", "D.")): # Answer option detected
98
+ current_question += f"\n {line}" # Add with proper indentation
99
  elif line: # Any additional text
100
+ current_question += f"\n {line}" # Continue the current question
101
 
102
  # Append the last question
103
  if current_question:
104
  formatted.append(current_question.strip())
105
+ return("\n".join(formatted))
 
 
106
 
107
  def format_answers(answers):
108
  """Format answers to display with consistent alignment."""
 
134
  except Exception as e:
135
  return f"Error: {str(e)}", ""
136
 
137
+ # Define Gradio interface
138
  # Define Gradio interface
139
  with gr.Blocks() as demo:
140
  gr.Markdown("# Quiz App - Generate Questions")
 
155
  # Launch the app
156
  demo.launch()
157
 
158
+