Spaces:
Build error
Build error
| 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 | |
| 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) | |
| 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) | |