vinayakj02 commited on
Commit
5fb39b0
β€’
1 Parent(s): 2a0ce8a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -24
app.py CHANGED
@@ -1,41 +1,56 @@
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()
 
1
  import gradio as gr
2
  import pandas as pd
3
  import random
4
+ from transformers import DebertaV2Tokenizer, DebertaV2Model
5
 
6
+ # Importing and setting up a DeBERTa v2 model (for demonstration)
7
+ tokenizer = DebertaV2Tokenizer.from_pretrained('microsoft/deberta-v2-xlarge')
8
+ model = DebertaV2Model.from_pretrained('microsoft/deberta-v2-xlarge')
9
+
10
+ # Hardcoded sample data
11
+ data = {
12
+ "QueryID": [
13
+ "Tastemade _16_46", "MyChart _23_23", "USPS MOBILE _20_10",
14
+ "The Washington Post Classic _21_20", "QuickBooks Accounting: Invoicing & Expenses _9_40"
15
+ ],
16
+ "Segment": [
17
+ "Some common applications are to target adverti...",
18
+ "The security of your information and data whil...",
19
+ "If you still have concerns about cookies, you ...",
20
+ "cookies help us and third parties understand ...",
21
+ "Under certain conditions, more fully described..."
22
+ ]
23
+ }
24
+
25
+ df = pd.DataFrame(data)
26
+
27
+ # Fake predictions for demonstration
28
  fake_predictions = {
29
+ "Tastemade _16_46": "Irrelevant",
30
+ "MyChart _23_23": "Irrelevant",
31
+ "USPS MOBILE _20_10": "Irrelevant",
32
+ "The Washington Post Classic _21_20": "Irrelevant",
33
+ "QuickBooks Accounting: Invoicing & Expenses _9_40": "Irrelevant",
34
+ # ... Add more mappings if needed
35
  }
36
 
37
+ def preprocess_data(segment):
38
+ # Sample preprocessing steps (not actually applied in fake prediction)
39
+ tokenized_input = tokenizer(segment, return_tensors="pt", padding='max_length', truncation=True, max_length=512)
40
+ # Normally, you would pass this through the model, but here we're just simulating
41
+ return tokenized_input
42
+
43
  def predict(query_id):
44
  # Simulate a model prediction
45
+ segment = df[df['QueryID'] == query_id]['Segment'].iloc[0]
46
+ processed_data = preprocess_data(segment) # Preprocessing (for show)
47
  response = fake_predictions.get(query_id, "Unknown QueryID")
48
  return response
49
 
 
 
 
 
 
50
  iface = gr.Interface(
51
  fn=predict,
52
+ inputs=gr.inputs.Dropdown(list(df['QueryID'].unique()), label="Select QueryID"),
53
+ outputs="text"
 
54
  )
55
 
56
  iface.launch()