sjw commited on
Commit
1556bff
·
1 Parent(s): f867f74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -16
app.py CHANGED
@@ -43,6 +43,7 @@ repo = Repository(
43
 
44
 
45
  def generate_html() -> str:
 
46
  with open(DATA_FILE) as csvfile:
47
  reader = csv.DictReader(csvfile)
48
  rows = []
@@ -63,6 +64,7 @@ def generate_html() -> str:
63
 
64
 
65
  def store_message(name: str, message: str):
 
66
  if name and message:
67
  with open(DATA_FILE, "a") as csvfile:
68
  writer = csv.DictWriter(csvfile, fieldnames=["name", "message", "time"])
@@ -73,20 +75,12 @@ def store_message(name: str, message: str):
73
  return generate_html()
74
 
75
 
76
- iface = gr.Interface(
77
- store_message,
78
- [
79
- components.Textbox(placeholder="Your name"),
80
- components.Textbox(placeholder="Your message", lines=2),
81
- ],
82
- "html",
83
- css="""
84
- .name {background-color:cornflowerblue;color:white; padding:4px;margin:4px;border-radius:4px; }
85
- """,
86
- title="Reading/writing to a HuggingFace dataset repo from Spaces",
87
- description=f"This is a demo of how to do simple *shared data persistence* in a Gradio Space, backed by a dataset repo.",
88
- article=f"The dataset repo is [{DATASET_REPO_URL}]({DATASET_REPO_URL})",
89
- allow_flagging="never"
90
- )
91
 
92
- iface.launch()
 
43
 
44
 
45
  def generate_html() -> str:
46
+ """Generate HTML content for the chat."""
47
  with open(DATA_FILE) as csvfile:
48
  reader = csv.DictReader(csvfile)
49
  rows = []
 
64
 
65
 
66
  def store_message(name: str, message: str):
67
+ """Store the message and regenerate HTML content."""
68
  if name and message:
69
  with open(DATA_FILE, "a") as csvfile:
70
  writer = csv.DictWriter(csvfile, fieldnames=["name", "message", "time"])
 
75
  return generate_html()
76
 
77
 
78
+ with gr.Blocks() as feedback_page:
79
+ gr.Markdown(f"Live Dataset: [{DATASET_REPO_URL}]({DATASET_REPO_URL})")
80
+ name_input = components.Textbox(label="Your Username")
81
+ message_input = components.Textbox(label="Your Feedback", lines=2)
82
+ output_html = gr.HTML()
83
+ submit_button = gr.Button("Submit")
84
+ submit_button.click(store_message, inputs=[name_input, message_input], outputs=output_html)
 
 
 
 
 
 
 
 
85
 
86
+ feedback_page.launch()