DeBERTav2 / app.py
vinayakj02's picture
Update app.py
5fb39b0
import gradio as gr
import pandas as pd
import random
from transformers import DebertaV2Tokenizer, DebertaV2Model
# Importing and setting up a DeBERTa v2 model (for demonstration)
tokenizer = DebertaV2Tokenizer.from_pretrained('microsoft/deberta-v2-xlarge')
model = DebertaV2Model.from_pretrained('microsoft/deberta-v2-xlarge')
# Hardcoded sample data
data = {
"QueryID": [
"Tastemade _16_46", "MyChart _23_23", "USPS MOBILE _20_10",
"The Washington Post Classic _21_20", "QuickBooks Accounting: Invoicing & Expenses _9_40"
],
"Segment": [
"Some common applications are to target adverti...",
"The security of your information and data whil...",
"If you still have concerns about cookies, you ...",
"cookies help us and third parties understand ...",
"Under certain conditions, more fully described..."
]
}
df = pd.DataFrame(data)
# Fake predictions for demonstration
fake_predictions = {
"Tastemade _16_46": "Irrelevant",
"MyChart _23_23": "Irrelevant",
"USPS MOBILE _20_10": "Irrelevant",
"The Washington Post Classic _21_20": "Irrelevant",
"QuickBooks Accounting: Invoicing & Expenses _9_40": "Irrelevant",
# ... Add more mappings if needed
}
def preprocess_data(segment):
# Sample preprocessing steps (not actually applied in fake prediction)
tokenized_input = tokenizer(segment, return_tensors="pt", padding='max_length', truncation=True, max_length=512)
# Normally, you would pass this through the model, but here we're just simulating
return tokenized_input
def predict(query_id):
# Simulate a model prediction
segment = df[df['QueryID'] == query_id]['Segment'].iloc[0]
processed_data = preprocess_data(segment) # Preprocessing (for show)
response = fake_predictions.get(query_id, "Unknown QueryID")
return response
iface = gr.Interface(
fn=predict,
inputs=gr.inputs.Dropdown(list(df['QueryID'].unique()), label="Select QueryID"),
outputs="text"
)
iface.launch()