File size: 1,249 Bytes
10e9b7d 39759b0 3c4371f 10e9b7d 39759b0 e80aab9 39759b0 4021bf3 39759b0 31243f4 39759b0 31243f4 39759b0 31243f4 39759b0 31243f4 39759b0 e80aab9 39759b0 e80aab9 39759b0 7d65c66 39759b0 3c4371f 39759b0 |
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 |
import gradio as gr
from datasets import load_dataset
from transformers import pipeline
import pandas as pd
def run_evaluation():
# Load your custom dataset
dataset = load_dataset("JAIKRISHVK/qa_dataset")
questions = dataset["train"]
# Load model
model = pipeline("text2text-generation", model="google/flan-t5-base")
results = []
for item in questions:
question = item.get("Question") or item.get("question") or ""
try:
output = model(question, max_length=50)
answer = output[0].get("generated_text", "").strip()
except Exception as e:
answer = f"Error: {e}"
results.append({"Question": question, "Answer": answer})
# Convert to DataFrame
df = pd.DataFrame(results)
# Save to CSV file
file_path = "/tmp/generated_answers.csv"
df.to_csv(file_path, index=False)
return df, file_path
# Gradio Interface
with gr.Blocks() as demo:
gr.Markdown("## AI Question Answer Evaluation")
submit_btn = gr.Button("RUN EVALUATION & SUBMIT ALL ANSWERS")
output_table = gr.DataFrame()
download_file = gr.File(label="Download CSV")
submit_btn.click(fn=run_evaluation, outputs=[output_table, download_file])
demo.launch()
|