Spaces:
Runtime error
Runtime error
vinayakj02
commited on
Commit
β’
5fb39b0
1
Parent(s):
2a0ce8a
Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,56 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import random
|
|
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
fake_predictions = {
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
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(
|
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()
|