Spaces:
Runtime error
Runtime error
Commit
β’
c7e50b8
1
Parent(s):
ea8df7f
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import random
|
4 |
+
|
5 |
+
# Sample data: Replace this with your legal QA dataset structure
|
6 |
+
# Assuming columns: 'DocID', 'QueryID', 'Query', 'Segment', 'Label'
|
7 |
+
sample_data = pd.DataFrame({
|
8 |
+
'DocID': ['Doc1', 'Doc2', 'Doc3', 'Doc4', 'Doc5'],
|
9 |
+
'QueryID': [101, 102, 103, 104, 105],
|
10 |
+
'Query': ['What is the law regarding...', 'How is the case...', 'Definition of legal term...', 'Procedure for filing...', 'Rights of an individual...'],
|
11 |
+
'Segment': ['Segment1', 'Segment2', 'Segment3', 'Segment4', 'Segment5'],
|
12 |
+
'Label': [1, 0, 1, 0, 1] # Sample labels
|
13 |
+
})
|
14 |
+
|
15 |
+
# Fake predictions: You should replace these with actual predictions from your test set
|
16 |
+
fake_predictions = {
|
17 |
+
101: 'Positive Response',
|
18 |
+
102: 'Negative Response',
|
19 |
+
103: 'Positive Response',
|
20 |
+
104: 'Negative Response',
|
21 |
+
105: 'Positive Response'
|
22 |
+
}
|
23 |
+
|
24 |
+
def predict(query_id):
|
25 |
+
# Simulate a model prediction
|
26 |
+
response = fake_predictions.get(query_id, "Unknown QueryID")
|
27 |
+
return response
|
28 |
+
|
29 |
+
def get_random_row():
|
30 |
+
# Get a random row from the dataset for demonstration
|
31 |
+
random_row = sample_data.sample().iloc[0]
|
32 |
+
return f"DocID: {random_row['DocID']}, QueryID: {random_row['QueryID']}, Query: {random_row['Query']}, Segment: {random_row['Segment']}"
|
33 |
+
|
34 |
+
iface = gr.Interface(
|
35 |
+
fn=predict,
|
36 |
+
inputs=gr.inputs.Dropdown(list(sample_data['QueryID']), label="Select QueryID"),
|
37 |
+
outputs="text",
|
38 |
+
examples=[get_random_row() for _ in range(5)]
|
39 |
+
)
|
40 |
+
|
41 |
+
iface.launch()
|