taruschirag commited on
Commit
70a7dfd
·
verified ·
1 Parent(s): 440d192

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -10
app.py CHANGED
@@ -127,11 +127,9 @@ class ModelWrapper:
127
  thinking_answer_text = remainder.split("</transcript>")[-1]
128
  return thinking_answer_text
129
  except:
130
- # If parsing fails, return the portion after the input
131
  input_length = len(message)
132
  return output_text[input_length:] if len(output_text) > input_length else "No response generated."
133
 
134
- # — instantiate your model —
135
  MODEL_NAME = "Qwen/Qwen3-0.6B"
136
  model = ModelWrapper(MODEL_NAME)
137
 
@@ -141,21 +139,17 @@ def compliance_check(rules_text, transcript_text, thinking):
141
  rules = [r for r in rules_text.split("\n") if r.strip()]
142
  inp = format_rules(rules) + format_transcript(transcript_text)
143
 
144
- # Limit max tokens to prevent oversized responses
145
  out = model.get_response(inp, enable_thinking=thinking, max_new_tokens=256)
146
 
147
- # Clean up any malformed output and ensure it's a string
148
  out = str(out).strip()
149
  if not out:
150
  out = "No response generated. Please try with different input."
151
 
152
- # Ensure the response isn't too long for an HTTP response by checking byte length
153
- max_bytes = 2500 # A more generous limit, in bytes
154
  out_bytes = out.encode('utf-8')
155
 
156
  if len(out_bytes) > max_bytes:
157
- # Truncate the byte string, then decode back to a string, ignoring errors
158
- # This prevents cutting a multi-byte character in half
159
  truncated_bytes = out_bytes[:max_bytes]
160
  out = truncated_bytes.decode('utf-8', errors='ignore')
161
  out += "\n\n[Response truncated to prevent server errors]"
@@ -163,12 +157,11 @@ def compliance_check(rules_text, transcript_text, thinking):
163
  return out
164
 
165
  except Exception as e:
166
- error_msg = f"Error: {str(e)[:200]}" # Limit error message length
167
  print(f"Full error: {e}")
168
  return error_msg
169
 
170
 
171
- # — build Gradio interface —
172
  demo = gr.Interface(
173
  fn=compliance_check,
174
  inputs=[
 
127
  thinking_answer_text = remainder.split("</transcript>")[-1]
128
  return thinking_answer_text
129
  except:
 
130
  input_length = len(message)
131
  return output_text[input_length:] if len(output_text) > input_length else "No response generated."
132
 
 
133
  MODEL_NAME = "Qwen/Qwen3-0.6B"
134
  model = ModelWrapper(MODEL_NAME)
135
 
 
139
  rules = [r for r in rules_text.split("\n") if r.strip()]
140
  inp = format_rules(rules) + format_transcript(transcript_text)
141
 
 
142
  out = model.get_response(inp, enable_thinking=thinking, max_new_tokens=256)
143
 
 
144
  out = str(out).strip()
145
  if not out:
146
  out = "No response generated. Please try with different input."
147
 
148
+ max_bytes = 2500
 
149
  out_bytes = out.encode('utf-8')
150
 
151
  if len(out_bytes) > max_bytes:
152
+
 
153
  truncated_bytes = out_bytes[:max_bytes]
154
  out = truncated_bytes.decode('utf-8', errors='ignore')
155
  out += "\n\n[Response truncated to prevent server errors]"
 
157
  return out
158
 
159
  except Exception as e:
160
+ error_msg = f"Error: {str(e)[:200]}"
161
  print(f"Full error: {e}")
162
  return error_msg
163
 
164
 
 
165
  demo = gr.Interface(
166
  fn=compliance_check,
167
  inputs=[