Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load a pre-trained question-answering pipeline
|
5 |
+
qa_pipeline = pipeline('question-answering', model='distilbert-base-uncased-distilled-squad')
|
6 |
+
|
7 |
+
def answer_question(question, context):
|
8 |
+
# Use the pre-trained pipeline to answer questions
|
9 |
+
result = qa_pipeline({'question': question, 'context': context})
|
10 |
+
return result['answer']
|
11 |
+
|
12 |
+
def log_feedback(question, context, answer, correct, feedback):
|
13 |
+
print(f"Question: {question}")
|
14 |
+
print(f"Context: {context}")
|
15 |
+
print(f"Answer: {answer}")
|
16 |
+
print(f"Correct: {correct}")
|
17 |
+
print(f"Feedback: {feedback}")
|
18 |
+
# Here you can add code to save feedback to a file or a database
|
19 |
+
|
20 |
+
# Define the context about the Enron scandal
|
21 |
+
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."
|
22 |
+
|
23 |
+
# Create the Gradio interface
|
24 |
+
iface = gr.Interface(
|
25 |
+
fn=answer_question,
|
26 |
+
inputs=[
|
27 |
+
gr.Textbox(lines=2, placeholder="Enter a question about the Enron case"),
|
28 |
+
gr.Textbox(value=enron_context, lines=10, placeholder="Context for the question", label="Context")
|
29 |
+
],
|
30 |
+
outputs=[gr.Text(label="Answer")],
|
31 |
+
title="Enron Case Question Answering System",
|
32 |
+
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.",
|
33 |
+
examples=[["What was the Enron scandal?", enron_context], ["What happened to Arthur Andersen?", enron_context]]
|
34 |
+
)
|
35 |
+
|
36 |
+
# Add a feedback form
|
37 |
+
feedback_form = gr.Interface(
|
38 |
+
fn=log_feedback,
|
39 |
+
inputs=[
|
40 |
+
gr.Textbox(label="Question Asked"),
|
41 |
+
gr.Textbox(label="Context Given"),
|
42 |
+
gr.Textbox(label="Answer Provided"),
|
43 |
+
gr.Radio(choices=["Yes", "No"], label="Was the answer correct?"),
|
44 |
+
gr.Textbox(label="Additional Feedback")
|
45 |
+
],
|
46 |
+
outputs=[]
|
47 |
+
)
|
48 |
+
|
49 |
+
iface.launch()
|