Spaces:
Build error
Build error
File size: 2,759 Bytes
441d880 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | from typing import List, Optional
from pydantic import BaseModel
import pandas as pd
from itertools import groupby
class QAEntry(BaseModel):
Num: int
Section: str
Question: str
Expected_Output: Optional[str]
Respondent: Optional[str]
Answer: Optional[str]
class InterviewReport(BaseModel):
Entries: List[QAEntry]
def __repr__(self):
output = ""
for section, entries in groupby(self.Entries, key=lambda entry: entry.Section):
output += f"{section}:\n"
for entry in entries:
output += f"Q {entry.Num}: {entry.Question}\n"
output += f"Expected Output: {entry.Expected_Output if entry.Expected_Output else 'No Expected Output'}\n"
output += f"Respondent: {entry.Respondent if entry.Respondent else 'No Respondent'}\n"
output += f"A: {entry.Answer if entry.Answer else 'No Answer'}\n"
return output
def get_respondent_responses(self,respondent):
respondent_entries = [
entry for entry in self.Entries
if entry.Respondent and entry.Respondent.lower() == respondent.lower()
]
return respondent_entries
@staticmethod
def generate_interview_script(interview_file):
df = pd.read_excel(interview_file)
qa_entries = []
for idx, row in enumerate(df.to_dict('records')):
print(f"Processing row {idx}: {row}") # Debug: show the full row being processed
entry = QAEntry(
Num = row['Num'],
Section = row['Section'],
Question = row['Question'],
Expected_Output = row.get('Expected_Output') if pd.notna(row.get('Expected_Output')) else None,
Respondent = None,
Answer = None
)
qa_entries.append(entry)
return InterviewReport(Entries = qa_entries)
@staticmethod
def generate_interview_report(interview_file):
df = pd.read_excel(interview_file)
qa_entries = [
QAEntry(
Num = row['Num'],
Section = row['Section'],
Question = row['Question'],
Expected_Output = row.get('Expected_Output') if pd.notna(row.get('Expected_Output')) else "No Expected Output Provided",
Respondent = row.get('Respondent') if pd.notna(row.get('Respondent')) else "No Respondent Provided",
Answer = row.get('Answer') if pd.notna(row.get('Answer')) else "No Answer Provided"
)
for row in df.to_dict('records')
]
return InterviewReport(Entries = qa_entries)
|