Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,14 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from transformers import pipeline
|
3 |
-
from datasets import load_dataset
|
4 |
|
5 |
-
#
|
6 |
model_name = "Qwen/Qwen2.5-3B"
|
7 |
-
|
8 |
-
# Load model pipeline
|
9 |
pipe = pipeline("text-generation", model=model_name, device=0)
|
10 |
|
11 |
-
# Load GTA
|
12 |
-
|
|
|
13 |
|
14 |
def run_model(input_text, use_gta_index):
|
15 |
if use_gta_index:
|
@@ -17,23 +16,22 @@ def run_model(input_text, use_gta_index):
|
|
17 |
index = int(input_text)
|
18 |
question = gta_data[index]["question"]
|
19 |
except Exception as e:
|
20 |
-
return f"β
|
21 |
else:
|
22 |
question = input_text
|
23 |
|
24 |
output = pipe(question, max_new_tokens=256, do_sample=True)
|
25 |
return f"**Question:** {question}\n\n**Response:**\n{output[0]['generated_text']}"
|
26 |
|
27 |
-
# Gradio UI
|
28 |
with gr.Blocks() as demo:
|
29 |
-
gr.Markdown("# π€ GTA
|
30 |
-
gr.Markdown("
|
31 |
with gr.Row():
|
32 |
-
input_text = gr.Textbox(label="Enter a question or GTA index (
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
|
37 |
-
|
38 |
|
39 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import json
|
3 |
from transformers import pipeline
|
|
|
4 |
|
5 |
+
# Load Qwen2.5-3B (should fit in 16GB with CPU)
|
6 |
model_name = "Qwen/Qwen2.5-3B"
|
|
|
|
|
7 |
pipe = pipeline("text-generation", model=model_name, device=0)
|
8 |
|
9 |
+
# β
Load local GTA dataset (test set)
|
10 |
+
with open("gta_test.json", "r", encoding="utf-8") as f:
|
11 |
+
gta_data = json.load(f)
|
12 |
|
13 |
def run_model(input_text, use_gta_index):
|
14 |
if use_gta_index:
|
|
|
16 |
index = int(input_text)
|
17 |
question = gta_data[index]["question"]
|
18 |
except Exception as e:
|
19 |
+
return f"β Invalid index: {e}"
|
20 |
else:
|
21 |
question = input_text
|
22 |
|
23 |
output = pipe(question, max_new_tokens=256, do_sample=True)
|
24 |
return f"**Question:** {question}\n\n**Response:**\n{output[0]['generated_text']}"
|
25 |
|
|
|
26 |
with gr.Blocks() as demo:
|
27 |
+
gr.Markdown("# π€ GTA Reasoning with Qwen2.5-3B")
|
28 |
+
gr.Markdown("Use a GTA query by index or enter your own.")
|
29 |
with gr.Row():
|
30 |
+
input_text = gr.Textbox(label="Enter a question or GTA index (0β228)")
|
31 |
+
use_index = gr.Checkbox(label="Treat input as GTA index", value=False)
|
32 |
+
run_btn = gr.Button("Generate")
|
33 |
+
output_md = gr.Markdown()
|
34 |
|
35 |
+
run_btn.click(run_model, inputs=[input_text, use_index], outputs=output_md)
|
36 |
|
37 |
demo.launch()
|