File size: 1,258 Bytes
cc2c826
6a02f5c
cc2c826
 
6a02f5c
cba37a7
5ed5886
 
6a02f5c
 
 
cc2c826
5ed5886
 
 
 
 
 
6a02f5c
cc2c826
5ed5886
cc2c826
 
5ed5886
cc2c826
 
6a02f5c
 
cc2c826
6a02f5c
 
 
 
cc2c826
6a02f5c
cc2c826
cba37a7
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
import gradio as gr
import json
from transformers import pipeline

# Load Qwen2.5-3B (should fit in 16GB with CPU)
model_name = "Qwen/Qwen2.5-3B"
pipe = pipeline("text-generation", model=model_name, device=0)

# βœ… Load local GTA dataset (test set)
with open("gta_test.json", "r", encoding="utf-8") as f:
    gta_data = json.load(f)

def run_model(input_text, use_gta_index):
    if use_gta_index:
        try:
            index = int(input_text)
            question = gta_data[index]["question"]
        except Exception as e:
            return f"❌ Invalid index: {e}"
    else:
        question = input_text

    output = pipe(question, max_new_tokens=256, do_sample=True)
    return f"**Question:** {question}\n\n**Response:**\n{output[0]['generated_text']}"

with gr.Blocks() as demo:
    gr.Markdown("# πŸ€– GTA Reasoning with Qwen2.5-3B")
    gr.Markdown("Use a GTA query by index or enter your own.")
    with gr.Row():
        input_text = gr.Textbox(label="Enter a question or GTA index (0–228)")
        use_index = gr.Checkbox(label="Treat input as GTA index", value=False)
    run_btn = gr.Button("Generate")
    output_md = gr.Markdown()
    
    run_btn.click(run_model, inputs=[input_text, use_index], outputs=output_md)

demo.launch()