Spaces:
Sleeping
Sleeping
Serhan Yılmaz
commited on
Commit
·
c24672d
1
Parent(s):
800222f
update app
Browse files
app.py
CHANGED
|
@@ -8,6 +8,8 @@ import logging
|
|
| 8 |
import json
|
| 9 |
import gradio as gr
|
| 10 |
import pandas as pd
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Set up logging
|
| 13 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -18,6 +20,9 @@ co = cohere.Client(api_key=os.environ.get("COHERE_API_KEY"))
|
|
| 18 |
sentence_model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 19 |
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
# Define sample inputs
|
| 22 |
samples = [
|
| 23 |
{
|
|
@@ -166,10 +171,16 @@ def gradio_interface(context: str, answer: str) -> Tuple[pd.DataFrame, pd.DataFr
|
|
| 166 |
def use_sample(sample_index: int) -> Tuple[str, str]:
|
| 167 |
return samples[sample_index]["context"], samples[sample_index]["answer"]
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
# Create Gradio interface with improved layout and sample buttons
|
| 170 |
with gr.Blocks(theme=gr.themes.Default()) as iface:
|
| 171 |
gr.Markdown("# Question Generator and Ranker")
|
| 172 |
-
gr.Markdown("Enter a context and an answer to generate and rank questions,
|
| 173 |
|
| 174 |
with gr.Row():
|
| 175 |
with gr.Column(scale=1):
|
|
@@ -179,6 +190,7 @@ with gr.Blocks(theme=gr.themes.Default()) as iface:
|
|
| 179 |
|
| 180 |
with gr.Row():
|
| 181 |
sample_buttons = [gr.Button(f"Sample {i+1}") for i in range(3)]
|
|
|
|
| 182 |
|
| 183 |
with gr.Column(scale=2):
|
| 184 |
best_question_output = gr.Textbox(label="Best Question")
|
|
@@ -216,5 +228,11 @@ with gr.Blocks(theme=gr.themes.Default()) as iface:
|
|
| 216 |
outputs=[context_input, answer_input]
|
| 217 |
)
|
| 218 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
# Launch the app
|
| 220 |
iface.launch()
|
|
|
|
| 8 |
import json
|
| 9 |
import gradio as gr
|
| 10 |
import pandas as pd
|
| 11 |
+
from datasets import load_dataset
|
| 12 |
+
import random
|
| 13 |
|
| 14 |
# Set up logging
|
| 15 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 20 |
sentence_model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 21 |
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
| 22 |
|
| 23 |
+
# Load the dataset
|
| 24 |
+
dataset = load_dataset("serhany/scaling-qa")
|
| 25 |
+
|
| 26 |
# Define sample inputs
|
| 27 |
samples = [
|
| 28 |
{
|
|
|
|
| 171 |
def use_sample(sample_index: int) -> Tuple[str, str]:
|
| 172 |
return samples[sample_index]["context"], samples[sample_index]["answer"]
|
| 173 |
|
| 174 |
+
def get_random_entry():
|
| 175 |
+
# Get a random entry from the dataset
|
| 176 |
+
random_index = random.randint(0, len(dataset['train']) - 1)
|
| 177 |
+
entry = dataset['train'][random_index]
|
| 178 |
+
return entry['context'], entry['answer']
|
| 179 |
+
|
| 180 |
# Create Gradio interface with improved layout and sample buttons
|
| 181 |
with gr.Blocks(theme=gr.themes.Default()) as iface:
|
| 182 |
gr.Markdown("# Question Generator and Ranker")
|
| 183 |
+
gr.Markdown("Enter a context and an answer to generate and rank questions, use one of the sample inputs, or get a random entry from the dataset.")
|
| 184 |
|
| 185 |
with gr.Row():
|
| 186 |
with gr.Column(scale=1):
|
|
|
|
| 190 |
|
| 191 |
with gr.Row():
|
| 192 |
sample_buttons = [gr.Button(f"Sample {i+1}") for i in range(3)]
|
| 193 |
+
random_button = gr.Button("Random Dataset Entry")
|
| 194 |
|
| 195 |
with gr.Column(scale=2):
|
| 196 |
best_question_output = gr.Textbox(label="Best Question")
|
|
|
|
| 228 |
outputs=[context_input, answer_input]
|
| 229 |
)
|
| 230 |
|
| 231 |
+
# Set up random button functionality
|
| 232 |
+
random_button.click(
|
| 233 |
+
fn=get_random_entry,
|
| 234 |
+
outputs=[context_input, answer_input]
|
| 235 |
+
)
|
| 236 |
+
|
| 237 |
# Launch the app
|
| 238 |
iface.launch()
|