Team Ai
Apppublic

sango07/Test-Set-Generator

sourceHugging Faceupdated 2y agoView on Hugging Face
1likes
app.py118 linesDownload Raw Back to root
1import streamlit as st2import pandas as pd3import os4 5# Import the TestCaseGenerator6from test_case_generator import TestCaseGenerator7 8def main():9    st.set_page_config(10        page_title="Question Generation App", 11        page_icon="๐Ÿ“", 12        layout="wide"13    )14 15    # Custom CSS for styling16    st.markdown("""17    <style>18    .main-title {19        font-size: 3em;20        color: #2C3E50;21        text-align: center;22        margin-bottom: 30px;23    }24    .stButton>button {25        background-color: #3498DB;26        color: white;27        border: none;28        padding: 10px 20px;29        border-radius: 5px;30        transition: all 0.3s;31    }32    .stButton>button:hover {33        background-color: #2980B9;34        transform: scale(1.05);35    }36    </style>37    """, unsafe_allow_html=True)38 39    # Title40    st.markdown("<h1 class='main-title'>๐Ÿ“ AI Question Generator</h1>", unsafe_allow_html=True)41 42    # Sidebar for inputs43    st.sidebar.header("Configuration")44    45    # File uploader46    uploaded_file = st.sidebar.file_uploader(47        "Upload PDF Document", 48        type=['pdf'], 49        help="Please upload a PDF file to generate questions from"50    )51 52    # Question type selection53    generator = TestCaseGenerator()54    question_types = st.sidebar.multiselect(55        "Select Question Types", 56        generator.available_question_types,57        default=['hallucination', 'toxicity']58    )59 60    # Number of questions61    num_questions = st.sidebar.slider(62        "Number of Questions per Type", 63        min_value=1, 64        max_value=20, 65        value=566    )67 68    # Generate button69    generate_button = st.sidebar.button("Generate Questions", use_container_width=True)70 71    # Main content area72    main_content = st.container()73 74    # Generation logic75    if generate_button and uploaded_file and question_types:76        with st.spinner('Generating questions...'):77            # Create results DataFrame78            final_df = pd.DataFrame()79 80            # Generate questions for each selected type81            for q_type in question_types:82                try:83                    type_df = generator.generate_testcases(84                        uploaded_file, 85                        question_type=q_type, 86                        num_testcases=num_questions87                    )88                    type_df['question_type'] = q_type89                    final_df = pd.concat([final_df, type_df], ignore_index=True)90                except Exception as e:91                    st.error(f"Error generating {q_type} questions: {e}")92 93            # Display results94            if not final_df.empty:95                st.success(f"Generated {len(final_df)} questions!")96                97                # Display questions in an interactive table98                st.dataframe(99                    final_df[['question_type', 'question', 'answer']], 100                    use_container_width=True101                )102 103                # Download button for Excel104                csv = final_df.to_csv(index=False)105                st.download_button(106                    label="Download Questions as CSV", 107                    data=csv, 108                    file_name="generated_questions.csv", 109                    mime="text/csv"110                )111            else:112                st.warning("No questions could be generated. Please check your inputs.")113 114    elif not uploaded_file:115        st.info("Please upload a PDF document to start generating questions.")116 117if __name__ == "__main__":118    main()