willsh1997 commited on
Commit
4992ed2
·
1 Parent(s): 8384a4e

:sparkles: initial commit - probable facts

Browse files
.github/workflows/push_to_hub.yml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face hub
2
+ on:
3
+ push:
4
+ branches: [main]
5
+
6
+ # to run this workflow manually from the Actions tab
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ sync-to-hub:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ with:
15
+ fetch-depth: 0
16
+ lfs: true
17
+ - name: Push to hub
18
+ env:
19
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
20
+ run: git push https://willsh1997:$HF_TOKEN@huggingface.co/spaces/willsh1997/probable-fact-examples main
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Neutral Sd Dev
3
+ emoji: 👁
4
+ colorFrom: red
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: 5.12.0
8
+ app_file: gradio_neutral_input_func.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ short_description: neutral sd gradio dev space
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
probable_facts_examples_gradio.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import random
4
+ import io
5
+ import json
6
+ import uuid
7
+ import os
8
+
9
+ # Setup directories
10
+ BASE_DIR = os.path.abspath(os.path.dirname(__file__))
11
+ PROBABLE_FACTS_DIR = os.path.join(BASE_DIR, "probable_facts_storage")
12
+ HARD_FACTS_DIR = os.path.join(BASE_DIR, "hard_facts_storage")
13
+ os.makedirs(PROBABLE_FACTS_DIR, exist_ok=True)
14
+ os.makedirs(HARD_FACTS_DIR, exist_ok=True)
15
+
16
+
17
+ def save_probable_example(example_text: str):
18
+ """Save the example text"""
19
+
20
+ example_id = uuid.uuid4()
21
+
22
+ json_path = os.path.join(PROBABLE_FACTS_DIR, f"{example_id}.json")
23
+
24
+ # Save description
25
+ desc_json = {"example": example_text}
26
+ with open(json_path, "w") as f:
27
+ json.dump(desc_json, f)
28
+
29
+ return load_previous_examples()
30
+
31
+ def save_hard_example(example_text: str):
32
+ """Save the example text"""
33
+
34
+ example_id = uuid.uuid4()
35
+
36
+ json_path = os.path.join(HARD_FACTS_DIR, f"{example_id}.json")
37
+
38
+ # Save description
39
+ desc_json = {"example": example_text}
40
+ with open(json_path, "w") as f:
41
+ json.dump(desc_json, f)
42
+
43
+ return load_previous_examples()
44
+
45
+ def load_previous_examples():
46
+ """Load all previously saved examples. Works for both probable and hard"""
47
+ # probable examples load
48
+ probable_examples = []
49
+ for file in os.listdir(PROBABLE_FACTS_DIR):
50
+ if file.endswith(".json"):
51
+ json_path = os.path.join(PROBABLE_FACTS_DIR, file)
52
+ if os.path.exists(json_path):
53
+ with open(json_path, "r") as f:
54
+ example = json.load(f)["example"]
55
+ probable_examples.append(example)
56
+ probable_examples_df = pd.DataFrame(probable_examples, columns = ["previous probable fact examples"])
57
+
58
+ # hard facts examples
59
+ hard_examples = []
60
+ for file in os.listdir(HARD_FACTS_DIR):
61
+ if file.endswith(".json"):
62
+ json_path = os.path.join(HARD_FACTS_DIR, file)
63
+ if os.path.exists(json_path):
64
+ with open(json_path, "r") as f:
65
+ example = json.load(f)["example"]
66
+ hard_examples.append(example)
67
+ hard_examples_df = pd.DataFrame(hard_examples, columns = ["previous hard fact examples"])
68
+
69
+
70
+
71
+ return probable_examples_df, hard_examples_df
72
+
73
+ # Create the Gradio interface
74
+ with gr.Blocks() as demo:
75
+
76
+ with gr.Row():
77
+ probable_fact_input = gr.Textbox(info = "Input your probable fact example here!")
78
+ hard_fact_input = gr.Textbox(info = "Input your hard fact example here!")
79
+ with gr.Row():
80
+ probable_btn = gr.Button("save probable fact example")
81
+ hard_btn = gr.Button("save hard fact example")
82
+ with gr.Row():
83
+ with gr.Accordion("Previous Probable Facts Examples", open=False):
84
+ probable_list = gr.Dataframe(interactive = False)
85
+ with gr.Accordion("Previous Probable Facts Examples", open=False):
86
+ hard_list = gr.Dataframe(interactive = False)
87
+
88
+ #.style(grid=2, height="auto")
89
+ # Set up event handlers
90
+ probable_btn.click(
91
+ fn=save_probable_example,
92
+ inputs = [probable_fact_input],
93
+ outputs=[probable_list, hard_list]
94
+ )
95
+ hard_btn.click(
96
+ fn=save_hard_example,
97
+ inputs = [hard_fact_input],
98
+ outputs=[probable_list, hard_list]
99
+ )
100
+
101
+ # Load previous examples on startup
102
+ demo.load(
103
+ fn=load_previous_examples,
104
+ outputs=[probable_list, hard_list]
105
+ )
106
+
107
+ # Launch the app
108
+ if __name__ == "__main__":
109
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ pillow
2
+ tqdm
3
+ torch
4
+ transformers
5
+ diffusers
6
+ torchvision
7
+ spaces
8
+ gradio