maker-faire-bot / app.py
aldan.creo
HF app
a5ef230
raw
history blame
3.6 kB
import logging
import os
import gradio as gr
from dotenv import load_dotenv
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
load_dotenv()
def get_user_prompt():
return {
"images": [
"images/1.jpeg",
"images/1.jpeg",
"images/1.jpeg",
],
"labels": [
"A roll of string",
"A camera",
"A loudspeaker",
],
}
hf_writer = gr.HuggingFaceDatasetSaver(
hf_token=os.environ["HF_TOKEN"], dataset_name="acmc/maker-faire-bot", private=True
)
csv_writer = gr.CSVLogger(simplify_file_data=True)
theme = gr.themes.Default(primary_hue="cyan", secondary_hue="fuchsia")
with gr.Blocks(theme=theme) as demo:
with gr.Row() as header:
gr.Image(
"maker-faire-logo.webp",
show_download_button=False,
show_label=False,
show_share_button=False,
container=False,
# height=100,
scale=0.2,
)
gr.Markdown(
"""
# Maker Faire Bot
""",
visible=False,
)
user_prompt = gr.State(get_user_prompt())
gr.Markdown("""# Think about these objects...""")
gr.Markdown(
"""We want to teach the Maker Faire Bot some creativity. Help us get ideas on what you'd build!"""
)
with gr.Row(variant="panel") as row:
for i in range(len(user_prompt.value["images"])):
with gr.Column(variant="default") as col:
gr.Image(
user_prompt.value["images"][i],
label=user_prompt.value["labels"][i],
interactive=False,
show_download_button=False,
show_share_button=False,
)
user_answer_object = gr.Textbox(
autofocus=True,
placeholder="(example): An digital electronic guitar",
label="What would you build?",
)
user_answer_explanation = gr.TextArea(
autofocus=True,
label="How would you build it?",
# The example uses a roll of string, a camera, and a loudspeaker to build an electronic guitar.
placeholder="""To build an electronic guitar, I would:
1. Use the roll of string to create the strings of the guitar.
2. Use the camera to capture a live video of the hand movements. That way, I can use an AI model to predict the chords.
3. Using a computer vision model, identify where the fingers are placed on the strings.
4. Calculate the sounds that the loudspeaker should produce based on the finger placements.
5. Play the sound through the loudspeaker.
""",
)
csv_writer.setup(
components=[user_prompt, user_answer_object, user_answer_explanation],
flagging_dir="user_data_csv",
)
hf_writer.setup(
components=[user_prompt, user_answer_object, user_answer_explanation],
flagging_dir="user_data_hf",
)
submit_btn = gr.Button("Submit", variant="primary")
def log_results(prompt, object, explanation):
csv_writer.flag([prompt, object, explanation])
hf_writer.flag([prompt, object, explanation])
submit_btn.click(
log_results,
inputs=[user_prompt, user_answer_object, user_answer_explanation],
preprocess=False,
)
gr.Markdown(
"""
This is an experimental project. Your data is anonymous and will be used to train an AI model. By using this tool, you agree to our [policy](https://makerfaire.com/privacy).
"""
)
if __name__ == "__main__":
demo.launch()