Spaces:
Runtime error
Runtime error
aldan.creo
commited on
Commit
·
cb93205
1
Parent(s):
8f86068
More changes
Browse files- app.py +38 -20
- maker-faire-logo.webp +0 -0
app.py
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from utils import add_result
|
| 3 |
-
#import dotenv
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def submit_result(user_answer):
|
|
@@ -24,58 +31,69 @@ def get_user_prompt():
|
|
| 24 |
],
|
| 25 |
}
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
theme = gr.themes.Default(primary_hue="cyan", secondary_hue="fuchsia")
|
| 31 |
|
| 32 |
with gr.Blocks(theme=theme) as demo:
|
| 33 |
with gr.Row() as header:
|
| 34 |
gr.Image(
|
| 35 |
-
"maker-faire-logo.
|
| 36 |
show_download_button=False,
|
| 37 |
show_label=False,
|
| 38 |
show_share_button=False,
|
| 39 |
container=False,
|
| 40 |
-
#height=100,
|
| 41 |
-
scale=0.2
|
| 42 |
)
|
| 43 |
gr.Markdown(
|
| 44 |
"""
|
| 45 |
# Maker Faire Bot
|
| 46 |
""",
|
| 47 |
-
visible=False
|
| 48 |
)
|
| 49 |
|
| 50 |
-
|
| 51 |
-
user_prompt = get_user_prompt()
|
| 52 |
|
| 53 |
gr.Markdown("""# Think about these objects...""")
|
| 54 |
-
gr.Markdown(
|
|
|
|
|
|
|
| 55 |
with gr.Row(variant="panel") as row:
|
| 56 |
-
for i in range(len(user_prompt["images"])):
|
| 57 |
-
print(i)
|
| 58 |
with gr.Column(variant="default") as col:
|
| 59 |
gr.Image(
|
| 60 |
-
user_prompt["images"][i],
|
| 61 |
-
label=user_prompt["labels"][i],
|
| 62 |
interactive=False,
|
| 63 |
show_download_button=False,
|
| 64 |
show_share_button=False,
|
| 65 |
)
|
| 66 |
-
# gr.Text(user_prompt['labels'][i])
|
| 67 |
|
| 68 |
-
|
| 69 |
autofocus=True,
|
| 70 |
placeholder="(example): An electronic guitar",
|
| 71 |
label="What would you build?",
|
| 72 |
)
|
| 73 |
-
|
| 74 |
-
autofocus=True,
|
|
|
|
|
|
|
| 75 |
)
|
| 76 |
|
|
|
|
|
|
|
|
|
|
| 77 |
submit_btn = gr.Button("Submit", variant="primary")
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
gr.Markdown(
|
| 81 |
"""
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
import gradio as gr
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
|
| 7 |
from utils import add_result
|
|
|
|
| 8 |
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
logger.setLevel(logging.DEBUG)
|
| 11 |
+
|
| 12 |
+
load_dotenv()
|
| 13 |
|
| 14 |
|
| 15 |
def submit_result(user_answer):
|
|
|
|
| 31 |
],
|
| 32 |
}
|
| 33 |
|
| 34 |
+
|
| 35 |
+
hf_writer = gr.HuggingFaceDatasetSaver(
|
| 36 |
+
hf_token=os.environ["HF_TOKEN"], dataset_name="acmc/maker-faire-bot", private=True
|
| 37 |
+
)
|
| 38 |
+
csv_writer = gr.CSVLogger(simplify_file_data=True)
|
| 39 |
|
| 40 |
theme = gr.themes.Default(primary_hue="cyan", secondary_hue="fuchsia")
|
| 41 |
|
| 42 |
with gr.Blocks(theme=theme) as demo:
|
| 43 |
with gr.Row() as header:
|
| 44 |
gr.Image(
|
| 45 |
+
"maker-faire-logo.webp",
|
| 46 |
show_download_button=False,
|
| 47 |
show_label=False,
|
| 48 |
show_share_button=False,
|
| 49 |
container=False,
|
| 50 |
+
# height=100,
|
| 51 |
+
scale=0.2,
|
| 52 |
)
|
| 53 |
gr.Markdown(
|
| 54 |
"""
|
| 55 |
# Maker Faire Bot
|
| 56 |
""",
|
| 57 |
+
visible=False,
|
| 58 |
)
|
| 59 |
|
| 60 |
+
user_prompt = gr.State(get_user_prompt())
|
|
|
|
| 61 |
|
| 62 |
gr.Markdown("""# Think about these objects...""")
|
| 63 |
+
gr.Markdown(
|
| 64 |
+
"""We want to teach the Maker Faire Bot some creativity. Help us get ideas on what you'd build!"""
|
| 65 |
+
)
|
| 66 |
with gr.Row(variant="panel") as row:
|
| 67 |
+
for i in range(len(user_prompt.value["images"])):
|
|
|
|
| 68 |
with gr.Column(variant="default") as col:
|
| 69 |
gr.Image(
|
| 70 |
+
user_prompt.value["images"][i],
|
| 71 |
+
label=user_prompt.value["labels"][i],
|
| 72 |
interactive=False,
|
| 73 |
show_download_button=False,
|
| 74 |
show_share_button=False,
|
| 75 |
)
|
|
|
|
| 76 |
|
| 77 |
+
user_answer_object = gr.Textbox(
|
| 78 |
autofocus=True,
|
| 79 |
placeholder="(example): An electronic guitar",
|
| 80 |
label="What would you build?",
|
| 81 |
)
|
| 82 |
+
user_answer_explanation = gr.TextArea(
|
| 83 |
+
autofocus=True,
|
| 84 |
+
label="How would you build it?",
|
| 85 |
+
placeholder="""I'd use the camera to detect when the user touches the strings and make a sound using the loudspeakers when that happens.""",
|
| 86 |
)
|
| 87 |
|
| 88 |
+
csv_writer.setup(components=[user_prompt, user_answer_object, user_answer_explanation], flagging_dir="flagged_data_csv")
|
| 89 |
+
hf_writer.setup(components=[user_prompt, user_answer_object, user_answer_explanation], flagging_dir="flagged_data_hf")
|
| 90 |
+
|
| 91 |
submit_btn = gr.Button("Submit", variant="primary")
|
| 92 |
+
def log_results(prompt, object, explanation):
|
| 93 |
+
csv_writer.flag([prompt, object, explanation])
|
| 94 |
+
hf_writer.flag([prompt, object, explanation])
|
| 95 |
+
|
| 96 |
+
submit_btn.click(log_results, inputs=[user_prompt, user_answer_object, user_answer_explanation], preprocess=False)
|
| 97 |
|
| 98 |
gr.Markdown(
|
| 99 |
"""
|
maker-faire-logo.webp
ADDED
|