benchang323 commited on
Commit
6b99753
·
verified ·
1 Parent(s): db4566a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -12
app.py CHANGED
@@ -14,32 +14,50 @@ if not os.path.exists(DATA_FILE):
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")
 
14
  with open(DATA_FILE, "r") as file:
15
  stored_data = json.load(file)
16
 
17
+ # Function to add a new query with positive and negative responses
18
+ def add_query(category, query, positive1, positive2, negative1, negative2):
19
  global stored_data
 
20
 
21
+ # Create structured entry
22
+ new_entry = {
23
+ "Category": category,
24
+ "Query": query,
25
+ "Positive_1": positive1,
26
+ "Positive_2": positive2,
27
+ "Negative_1": negative1,
28
+ "Negative_2": negative2
29
+ }
30
+
31
+ stored_data.append(new_entry)
32
 
33
  # Save to JSON file
34
  with open(DATA_FILE, "w") as file:
35
  json.dump(stored_data, file, indent=4)
36
 
37
+ return f"Added query: {query} under category '{category}' with responses."
38
 
39
  # Gradio UI
40
  with gr.Blocks() as app:
41
+ gr.Markdown("# 📝 Query Storage App with Responses")
42
+ gr.Markdown("### Enter queries and their responses to store in a JSON file.")
43
 
44
  category_input = gr.Textbox(label="Category", placeholder="Enter category (e.g., Rhyme, Aviation and Math)")
45
+ query_input = gr.Textbox(label="Query", placeholder="Enter query text", lines=2)
46
+
47
+ gr.Markdown("### Provide Responses")
48
+ positive1_input = gr.Textbox(label="Positive Response 1", placeholder="Enter first positive response", lines=3)
49
+ positive2_input = gr.Textbox(label="Positive Response 2", placeholder="Enter second positive response", lines=3)
50
+ negative1_input = gr.Textbox(label="Negative Response 1", placeholder="Enter first negative response", lines=3)
51
+ negative2_input = gr.Textbox(label="Negative Response 2", placeholder="Enter second negative response", lines=3)
52
 
53
+ submit_button = gr.Button("Add Query")
54
  status_output = gr.Textbox(label="Status", interactive=False)
55
+
56
+ submit_button.click(
57
+ add_query,
58
+ inputs=[category_input, query_input, positive1_input, positive2_input, negative1_input, negative2_input],
59
+ outputs=status_output
60
+ )
61
 
62
  gr.Markdown("### Download Stored Queries:")
63
  download_button = gr.File(DATA_FILE, label="Download JSON")