Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# JSON file to store data
|
| 6 |
+
DATA_FILE = "queries.json"
|
| 7 |
+
|
| 8 |
+
# Load existing data if available
|
| 9 |
+
if os.path.exists(DATA_FILE):
|
| 10 |
+
with open(DATA_FILE, "r") as file:
|
| 11 |
+
stored_data = json.load(file)
|
| 12 |
+
else:
|
| 13 |
+
stored_data = []
|
| 14 |
+
|
| 15 |
+
# Function to add a new query
|
| 16 |
+
def add_query(category, query):
|
| 17 |
+
new_entry = {"Category": category, "Query": query}
|
| 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: {category} - {query}"
|
| 25 |
+
|
| 26 |
+
# Function to download the stored dataset
|
| 27 |
+
def download_json():
|
| 28 |
+
return DATA_FILE
|
| 29 |
+
|
| 30 |
+
# Gradio Interface
|
| 31 |
+
with gr.Blocks() as app:
|
| 32 |
+
gr.Markdown("# 📝 Query Collection App")
|
| 33 |
+
gr.Markdown("### Manually enter queries to store in a JSON file:")
|
| 34 |
+
|
| 35 |
+
category_input = gr.Textbox(label="Category")
|
| 36 |
+
query_input = gr.Textbox(label="Query")
|
| 37 |
+
submit_button = gr.Button("Add Query")
|
| 38 |
+
status_output = gr.Textbox(label="Status", interactive=False)
|
| 39 |
+
|
| 40 |
+
submit_button.click(add_query, inputs=[category_input, query_input], outputs=status_output)
|
| 41 |
+
|
| 42 |
+
gr.Markdown("### Download the stored dataset:")
|
| 43 |
+
download_button = gr.File(DATA_FILE, label="Download JSON")
|
| 44 |
+
|
| 45 |
+
app.launch()
|