import os from pathlib import Path import sqlite3 import gradio as gr from datasets import Dataset, DatasetDict # Connect to SQLite database conn = sqlite3.connect('votes.db') c = conn.cursor() # Create table if it doesn't exist c.execute('''CREATE TABLE IF NOT EXISTS votes (filename TEXT, uap_votes INTEGER, not_uap_votes INTEGER)''') # Load image data from the folder dataset_path = os.path.join(os.getcwd(), 'content/nuforc_reports') dataset = DatasetDict.from_disk(dataset_path) image_files = [example['file'] for example in dataset['train']] # Function to vote for an image def vote_for_image(filename, vote): if vote == 'UAP': c.execute("UPDATE votes SET uap_votes = uap_votes + 1 WHERE filename = ?", (filename,)) elif vote == 'Not UAP': c.execute("UPDATE votes SET not_uap_votes = not_uap_votes + 1 WHERE filename = ?", (filename,)) conn.commit() # Get vote counts for an image def get_vote_counts(filename): c.execute("SELECT uap_votes, not_uap_votes FROM votes WHERE filename = ?", (filename,)) row = c.fetchone() if row: return row else: c.execute("INSERT INTO votes (filename, uap_votes, not_uap_votes) VALUES (?, 0, 0)", (filename,)) conn.commit() return (0, 0) # Gradio interface image_select = gr.Dropdown(image_files, label="Select an image") votes = gr.RenderedHTML() with gr.Blocks() as demo: with gr.Row(): with gr.Column(): image = gr.Image(value=f"{dataset_path}/{image_files[0]}", shape=(400, 400)) with gr.Column(): uap_vote = gr.Button("UAP") not_uap_vote = gr.Button("Not UAP") image_select.change(lambda x: f"{dataset_path}/{x}", inputs=image_select, outputs=image) uap_vote.click(vote_for_image, inputs=[image_select, gr.Const("UAP")], outputs=None) not_uap_vote.click(vote_for_image, inputs=[image_select, gr.Const("Not UAP")], outputs=None) vote_counts = gr.Column() image_select.change(lambda x: gr.Markdown(f"**UAP votes**: {get_vote_counts(x)[0]}\n**Not UAP votes**: {get_vote_counts(x)[1]}"), inputs=image_select, outputs=vote_counts) demo.launch()import os from pathlib import Path import sqlite3 import gradio as gr from datasets import Dataset, DatasetDict # Connect to SQLite database conn = sqlite3.connect('votes.db') c = conn.cursor() # Create table if it doesn't exist c.execute('''CREATE TABLE IF NOT EXISTS votes (filename TEXT, uap_votes INTEGER, not_uap_votes INTEGER)''') # Load image data from the folder dataset_path = os.path.join(os.getcwd(), 'content/nuforc_reports') dataset = DatasetDict.from_disk(dataset_path) image_files = [example['file'] for example in dataset['train']] # Function to vote for an image def vote_for_image(filename, vote): if vote == 'UAP': c.execute("UPDATE votes SET uap_votes = uap_votes + 1 WHERE filename = ?", (filename,)) elif vote == 'Not UAP': c.execute("UPDATE votes SET not_uap_votes = not_uap_votes + 1 WHERE filename = ?", (filename,)) conn.commit() # Get vote counts for an image def get_vote_counts(filename): c.execute("SELECT uap_votes, not_uap_votes FROM votes WHERE filename = ?", (filename,)) row = c.fetchone() if row: return row else: c.execute("INSERT INTO votes (filename, uap_votes, not_uap_votes) VALUES (?, 0, 0)", (filename,)) conn.commit() return (0, 0) # Gradio interface image_select = gr.Dropdown(image_files, label="Select an image") votes = gr.RenderedHTML() with gr.Blocks() as demo: with gr.Row(): with gr.Column(): image = gr.Image(value=f"{dataset_path}/{image_files[0]}", shape=(400, 400)) with gr.Column(): uap_vote = gr.Button("UAP") not_uap_vote = gr.Button("Not UAP") image_select.change(lambda x: f"{dataset_path}/{x}", inputs=image_select, outputs=image) uap_vote.click(vote_for_image, inputs=[image_select, gr.Const("UAP")], outputs=None) not_uap_vote.click(vote_for_image, inputs=[image_select, gr.Const("Not UAP")], outputs=None) vote_counts = gr.Column() image_select.change(lambda x: gr.Markdown(f"**UAP votes**: {get_vote_counts(x)[0]}\n**Not UAP votes**: {get_vote_counts(x)[1]}"), inputs=image_select, outputs=vote_counts) demo.launch()