import gradio as gr from transformers import pipeline # Load a pre-trained question-answering pipeline qa_pipeline = pipeline('question-answering', model='distilbert-base-uncased-distilled-squad') def answer_question(question, context): # Use the pre-trained pipeline to answer questions result = qa_pipeline({'question': question, 'context': context}) return result['answer'] def log_feedback(question, context, answer, correct, feedback): print(f"Question: {question}") print(f"Context: {context}") print(f"Answer: {answer}") print(f"Correct: {correct}") print(f"Feedback: {feedback}") # Here you can add code to save feedback to a file or a database # Define the context about the Enron scandal enron_context = "The Enron scandal was an accounting scandal involving Enron Corporation, an American energy company based in Houston, Texas. When news of widespread fraud within the company became public in October 2001, the company declared bankruptcy, and its accounting firm, Arthur Andersen, was effectively dissolved." # Create the Gradio interface iface = gr.Interface( fn=answer_question, inputs=[ gr.Textbox(lines=2, placeholder="Enter a question about the Enron case"), gr.Textbox(value=enron_context, lines=10, placeholder="Context for the question", label="Context") ], outputs=[gr.Text(label="Answer")], title="Enron Case Question Answering System", description="This interface uses a pre-trained model to answer your questions about the Enron scandal. Provide the question and context and get your answer.", examples=[["What was the Enron scandal?", enron_context], ["What happened to Arthur Andersen?", enron_context]] ) # Add a feedback form feedback_form = gr.Interface( fn=log_feedback, inputs=[ gr.Textbox(label="Question Asked"), gr.Textbox(label="Context Given"), gr.Textbox(label="Answer Provided"), gr.Radio(choices=["Yes", "No"], label="Was the answer correct?"), gr.Textbox(label="Additional Feedback") ], outputs=[] ) iface.launch()