Blessin commited on
Commit
995e58e
·
1 Parent(s): 898e436

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -19
app.py CHANGED
@@ -1,35 +1,28 @@
1
- import openai
2
  import gradio as gr
3
- import requests
4
  import random
5
- from io import StringIO
6
  from datasets import load_dataset
7
 
8
- # Load the dataset from Hugging Face Spaces
9
  dataset = load_dataset("Blessin/dialogues-one-liners")
10
 
11
- # Get the column name for the dialogue data
12
- column_name = dataset.column_names[0]
13
-
14
- # Access the dialogue data
15
- DIALOGUES = dataset["train"][column_name]
16
 
17
  def generate_statement():
18
- # Generate a random statement from the dataset
19
- index = random.randint(0, len(DIALOGUES) - 1)
20
- return DIALOGUES[index]
21
 
22
  def main():
23
- # Define the UI components using gr.Interface
24
  interface = gr.Interface(
25
- fn=generate_statement, # Function to call on button press
26
- inputs=[], # No inputs required as we're just generating random dialogues
27
- outputs="text", # Output is a text area
28
- live=True, # Only generate statement after button press
29
- description="Press the button to generate a statement from our dataset."
30
  )
31
 
32
- # Launch the UI on Spaces
33
  interface.launch(share=True)
34
 
35
  if __name__ == "__main__":
 
 
1
  import gradio as gr
 
2
  import random
 
3
  from datasets import load_dataset
4
 
5
+ # Load the dataset from Hugging Face
6
  dataset = load_dataset("Blessin/dialogues-one-liners")
7
 
8
+ # Extract the dialogues from the dataset
9
+ DIALOGUES = dataset["train"]["dialogues"]
 
 
 
10
 
11
  def generate_statement():
12
+ """Return a random dialogue from the dataset."""
13
+ return random.choice(DIALOGUES)
 
14
 
15
  def main():
16
+ # Define the UI using gr.Interface
17
  interface = gr.Interface(
18
+ fn=generate_statement, # Function to call on button press
19
+ inputs=[], # No inputs required
20
+ outputs="text", # Output is a text area
21
+ live=False, # Only generate statement after button press
22
+ description="Press the button to generate a statement from the dataset."
23
  )
24
 
25
+ # Launch the UI
26
  interface.launch(share=True)
27
 
28
  if __name__ == "__main__":