Spaces:
Runtime error
Runtime error
File size: 2,103 Bytes
e8e247e 5e8be56 7438e40 5e8be56 435dfc5 9f1cf26 c0ac2c5 7438e40 5e8be56 7ddcdfa c8a8f0b 5e8be56 e4b5450 5e8be56 a862f54 5e8be56 6f1af31 5e8be56 a862f54 5e8be56 a862f54 4ebd536 a862f54 435dfc5 abba6e8 5e8be56 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
import gradio as gr
import json
from run_llm import template_all, prompt2_pos, prompt2_chunk, prompt2_parse, demon_pos, demon_chunk, demon_parse, model_mapping
from tqdm import tqdm
# Your existing code
theme = gr.themes.Soft()
with open('sample_uniform_1k_2.txt', 'r') as f:
selected_idx = f.readlines()
selected_idx = [int(i.strip()) for i in selected_idx]#[s:e]
gid_list = selected_idx[0]
ptb = []
with open('ptb.jsonl', 'r') as f:
for l in f:
ptb.append(json.loads(l))
# Function to process text based on model and task
def process_text(model_name, task, text):
for gid in tqdm(gid_list, desc='Query'):
text = ptb[gid]['text']
# Define prompts for each strategy based on the task
strategy_prompts = {
'Strategy 1': template_all.format(text),
'Strategy 2': {
'POS': prompt2_pos.format(text),
'Chunking': prompt2_chunk.format(text),
'Parsing': prompt2_parse.format(text),
}.get(task, "Invalid Task Selection for Strategy 2"),
'Strategy 3': {
'POS': demon_pos,
'Chunking': demon_chunk,
'Parsing': demon_parse,
}.get(task, "Invalid Task Selection for Strategy 3"),
}
# Get the selected prompt based on the strategy
prompt = strategy_prompts.get(model_name, "Invalid Model Selection")
# Add your logic to feed the prompt to the selected model and get the result
result = "Processed Result" # Replace this with your actual result
return result
# Dropdown options for model and task
model_options = list(model_mapping.keys())
task_options = ['POS', 'Chunking', 'Parsing']
# Gradio interface
iface = gr.Interface(
fn=process_text,
inputs=[
gr.Dropdown(model_options, label="Select Model"),
gr.Dropdown(task_options, label="Select Task"),
],
outputs=[
gr.Textbox(label="Strategy 1 QA Result"),
gr.Textbox(label="Strategy 2 Instruction Result"),
gr.Textbox(label="Strategy 3 Structured Prompting Result"),
],
theme = theme,
live=False,
)
iface.launch()
|