Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,26 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
3 |
|
4 |
+
# Load the tokenizer and model from Hugging Face
|
5 |
+
model_name = 'alexdong/query-reformulation-knowledge-base-t5-small'
|
6 |
+
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
7 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
8 |
|
9 |
+
# Define the function that will be run for every input
|
10 |
+
def generate_text(input_text):
|
11 |
+
input_ids = tokenizer(f"reformulate: {input_text}", return_tensors="pt").input_ids
|
12 |
+
output_ids = model.generate(input_ids, max_length=50)
|
13 |
+
decoded_output = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
14 |
+
return decoded_output
|
15 |
+
|
16 |
+
# Define the Gradio interface
|
17 |
+
iface = gr.Interface(
|
18 |
+
fn=generate_text,
|
19 |
+
inputs="text",
|
20 |
+
outputs="text",
|
21 |
+
title="Query Reformulation",
|
22 |
+
description="Enter a search query to see how the model rewrites it into RAG friendly subqueries.", # Description
|
23 |
+
)
|
24 |
+
|
25 |
+
# Display the interface
|
26 |
+
iface.launch()
|