Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -2,44 +2,46 @@ import gradio as gr
|
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# JSON file
|
| 6 |
DATA_FILE = "queries.json"
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
if os.path.exists(DATA_FILE):
|
| 10 |
-
with open(DATA_FILE, "
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
stored_data.append(new_entry)
|
| 19 |
|
| 20 |
# Save to JSON file
|
| 21 |
with open(DATA_FILE, "w") as file:
|
| 22 |
json.dump(stored_data, file, indent=4)
|
| 23 |
|
| 24 |
-
return f"Added
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
def download_json():
|
| 28 |
-
return DATA_FILE
|
| 29 |
-
|
| 30 |
-
# Gradio Interface
|
| 31 |
with gr.Blocks() as app:
|
| 32 |
-
gr.Markdown("# 📝 Query
|
| 33 |
-
gr.Markdown("###
|
| 34 |
|
| 35 |
-
category_input = gr.Textbox(label="Category")
|
| 36 |
-
query_input = gr.Textbox(label="
|
| 37 |
-
submit_button = gr.Button("Add
|
| 38 |
-
status_output = gr.Textbox(label="Status", interactive=False)
|
| 39 |
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
-
gr.Markdown("### Download
|
| 43 |
download_button = gr.File(DATA_FILE, label="Download JSON")
|
| 44 |
|
| 45 |
app.launch()
|
|
|
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Define JSON storage file
|
| 6 |
DATA_FILE = "queries.json"
|
| 7 |
|
| 8 |
+
# Ensure the file exists
|
| 9 |
+
if not os.path.exists(DATA_FILE):
|
| 10 |
+
with open(DATA_FILE, "w") as file:
|
| 11 |
+
json.dump([], file) # Initialize empty list
|
| 12 |
+
|
| 13 |
+
# Load existing data
|
| 14 |
+
with open(DATA_FILE, "r") as file:
|
| 15 |
+
stored_data = json.load(file)
|
| 16 |
+
|
| 17 |
+
# Function to add bulk queries
|
| 18 |
+
def add_bulk_queries(category, queries):
|
| 19 |
+
global stored_data
|
| 20 |
+
queries_list = queries.split("\n") # Split input by new lines
|
| 21 |
|
| 22 |
+
for query in queries_list:
|
| 23 |
+
if query.strip(): # Avoid empty lines
|
| 24 |
+
stored_data.append({"Category": category, "Query": query.strip()})
|
|
|
|
| 25 |
|
| 26 |
# Save to JSON file
|
| 27 |
with open(DATA_FILE, "w") as file:
|
| 28 |
json.dump(stored_data, file, indent=4)
|
| 29 |
|
| 30 |
+
return f"Added {len(queries_list)} queries under category '{category}'"
|
| 31 |
|
| 32 |
+
# Gradio UI
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
with gr.Blocks() as app:
|
| 34 |
+
gr.Markdown("# 📝 Bulk Query Input & Storage")
|
| 35 |
+
gr.Markdown("### Paste multiple queries and store them in a JSON file.")
|
| 36 |
|
| 37 |
+
category_input = gr.Textbox(label="Category", placeholder="Enter category (e.g., Rhyme, Aviation and Math)")
|
| 38 |
+
query_input = gr.Textbox(label="Queries (one per line)", lines=10, placeholder="Paste queries here...")
|
| 39 |
+
submit_button = gr.Button("Add Queries")
|
|
|
|
| 40 |
|
| 41 |
+
status_output = gr.Textbox(label="Status", interactive=False)
|
| 42 |
+
submit_button.click(add_bulk_queries, inputs=[category_input, query_input], outputs=status_output)
|
| 43 |
|
| 44 |
+
gr.Markdown("### Download Stored Queries:")
|
| 45 |
download_button = gr.File(DATA_FILE, label="Download JSON")
|
| 46 |
|
| 47 |
app.launch()
|