sejalkishan commited on
Commit
61b6f1c
·
verified ·
1 Parent(s): 0d4d60a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -22
app.py CHANGED
@@ -82,33 +82,30 @@ Q18: Is private sector experience allowed?
82
  Q19: Do references need to be identified?
83
  Q20: Is subcontracting permitted?
84
 
85
- Answer clearly and in the same format:
86
- Q1: ...
87
- A1: ...
88
- Q2: ...
89
- A2: ...
90
  ...
91
  """
92
 
93
  # 🧼 Cleaner
94
  def clean_output(raw_output):
95
- lines = raw_output.splitlines()
96
- cleaned_lines = []
97
- started = False
98
-
99
- for line in lines:
100
- if line.strip().startswith("Q1:"):
101
- started = True
102
- if started:
103
- cleaned_lines.append(line)
104
-
105
- stop_idx = len(cleaned_lines)
106
- for i, line in enumerate(cleaned_lines[5:], 5):
107
- if "CONTENT:" in line or "You are an expert" in line:
108
- stop_idx = i
109
- break
110
-
111
- return "\n".join(cleaned_lines[:stop_idx]).strip()
 
 
112
 
113
  # 🚀 Main analysis function
114
  @spaces.GPU(duration=150)
 
82
  Q19: Do references need to be identified?
83
  Q20: Is subcontracting permitted?
84
 
 
 
 
 
 
85
  ...
86
  """
87
 
88
  # 🧼 Cleaner
89
  def clean_output(raw_output):
90
+ # Find first valid Q1
91
+ start_idx = raw_output.find("Q1:")
92
+ if start_idx == -1:
93
+ return raw_output.strip()
94
+
95
+ cleaned = raw_output[start_idx:]
96
+
97
+ # Remove everything after second instance of Q1 (to drop repeated prompts)
98
+ second_q1 = cleaned.find("Q1:", 3) # skip first one
99
+ if second_q1 != -1:
100
+ cleaned = cleaned[:second_q1]
101
+
102
+ # Drop leftover instructions if they show up later
103
+ cut_phrases = ["You are an expert", "Now provide answers", "CONTENT:", "Answer clearly and in the same format:"]
104
+ for phrase in cut_phrases:
105
+ if phrase in cleaned:
106
+ cleaned = cleaned.split(phrase)[0]
107
+
108
+ return cleaned.strip()
109
 
110
  # 🚀 Main analysis function
111
  @spaces.GPU(duration=150)