rodolfoocampo commited on
Commit
0802045
1 Parent(s): 87c203d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -19
app.py CHANGED
@@ -2,6 +2,17 @@ import numpy as np
2
  import os
3
  import gradio as gr
4
  import openai
 
 
 
 
 
 
 
 
 
 
 
5
 
6
 
7
 
@@ -19,7 +30,7 @@ def continueStory(blank, messageHistory):
19
 
20
  story = response["choices"][0]["message"]["content"]
21
  messageHistory.append(response["choices"][0]["message"])
22
- print(messageHistory)
23
  return story, messageHistory
24
 
25
 
@@ -34,7 +45,6 @@ with gr.Blocks(css='''
34
  background-image: url('file=https://cdn.discordapp.com/attachments/941582479117127680/1080730421425344542/rodotcom_colorful_abstract_illustration_for_the_background_of_c_f1b331d7-6493-4a33-9063-345d31a66ddb.png');
35
 
36
  }
37
-
38
  h1 {
39
  font-size: 3rem;
40
  font-weight: 700;
@@ -42,20 +52,16 @@ with gr.Blocks(css='''
42
  margin-bottom: 1rem;
43
  color: white;
44
  }
45
-
46
  p {
47
  font-size: 1.25rem;
48
  margin-bottom: 2rem;
49
  color: white;
50
  }
51
-
52
-
53
  label {
54
  font-size: 1.25rem;
55
  font-weight: 500;
56
  margin-bottom: 0.5rem;
57
  }
58
-
59
  input[type="text"], textarea {
60
  font-size: 1.25rem;
61
  padding: 0.5rem;
@@ -63,7 +69,6 @@ with gr.Blocks(css='''
63
  border-radius: 5px;
64
  width: 100%;
65
  }
66
-
67
  .gradio-button {
68
  background-color: #2196f3;
69
  color: #fff;
@@ -74,13 +79,10 @@ with gr.Blocks(css='''
74
  cursor: pointer;
75
  transition: all 0.2s ease-in-out;
76
  }
77
-
78
  .gradio-button:hover {
79
  background-color: #0c7cd5;
80
  }
81
-
82
 
83
-
84
  ''') as demo:
85
  title = gr.HTML('''
86
  <div style="text-align: center;">
@@ -111,13 +113,13 @@ with gr.Blocks(css='''
111
  provideFeedbackBtn = gr.Button("Provide Feedback", elem_id="feedback-btn")
112
 
113
  with gr.Column(visible=False) as feedbackForm:
114
- gr.Radio(["1", "2", "3", "4", "5"], label="How would you rate the story")
115
- feedback_text = gr.Textbox(label='Any other comments?')
116
- submitFeedbackBtn = gr.Button("Submit Feedback", elem_id="submit-feedback-btn")
117
 
118
  with gr.Column(visible=False) as thankyou:
119
 
120
- feedback_text = gr.HTML("<h2>Thanks for your feeback!</h2>")
121
 
122
  with gr.Column(visible=False) as mesHistoryCol:
123
 
@@ -130,8 +132,18 @@ with gr.Blocks(css='''
130
  def show_feedback_text():
131
  return {feedbackForm: gr.update(visible=True)}
132
 
133
- def submitFeedback():
134
- return {thankyou: gr.update(visible=True), feedbackForm: gr.update(visible=False)}
 
 
 
 
 
 
 
 
 
 
135
 
136
  def generateStory(character):
137
 
@@ -165,7 +177,7 @@ with gr.Blocks(css='''
165
 
166
  story = response["choices"][0]["message"]["content"]
167
  messageHistory.append(response["choices"][0]["message"])
168
- print(messageHistory)
169
  return story, messageHistory
170
 
171
  def createNewStory():
@@ -184,9 +196,9 @@ with gr.Blocks(css='''
184
 
185
  provideFeedbackBtn.click(show_feedback_text, [], [feedbackForm])
186
 
187
- submitFeedbackBtn.click(submitFeedback, [], [thankyou, feedbackForm])
188
 
189
  newStoryBtn.click(createNewStory, [], [character, story_output, blank])
190
 
191
 
192
- demo.launch(debug=True, share=False)
 
2
  import os
3
  import gradio as gr
4
  import openai
5
+ import gspread
6
+ from oauth2client.service_account import ServiceAccountCredentials
7
+
8
+ # Define the credentials to access the Google Sheets API
9
+ SCOPE = ["https://www.googleapis.com/auth/drive"]
10
+ SERVICE_ACCOUNT_FILE = "./check"
11
+
12
+ os.environ['GOOGLE_SHEETS_TOKEN']
13
+ creds = ServiceAccountCredentials.from_json_keyfile_name(SERVICE_ACCOUNT_FILE, SCOPE)
14
+ client = gspread.authorize(creds)
15
+ sheet = client.open("Feedback").sheet1
16
 
17
 
18
 
 
30
 
31
  story = response["choices"][0]["message"]["content"]
32
  messageHistory.append(response["choices"][0]["message"])
33
+
34
  return story, messageHistory
35
 
36
 
 
45
  background-image: url('file=https://cdn.discordapp.com/attachments/941582479117127680/1080730421425344542/rodotcom_colorful_abstract_illustration_for_the_background_of_c_f1b331d7-6493-4a33-9063-345d31a66ddb.png');
46
 
47
  }
 
48
  h1 {
49
  font-size: 3rem;
50
  font-weight: 700;
 
52
  margin-bottom: 1rem;
53
  color: white;
54
  }
 
55
  p {
56
  font-size: 1.25rem;
57
  margin-bottom: 2rem;
58
  color: white;
59
  }
 
 
60
  label {
61
  font-size: 1.25rem;
62
  font-weight: 500;
63
  margin-bottom: 0.5rem;
64
  }
 
65
  input[type="text"], textarea {
66
  font-size: 1.25rem;
67
  padding: 0.5rem;
 
69
  border-radius: 5px;
70
  width: 100%;
71
  }
 
72
  .gradio-button {
73
  background-color: #2196f3;
74
  color: #fff;
 
79
  cursor: pointer;
80
  transition: all 0.2s ease-in-out;
81
  }
 
82
  .gradio-button:hover {
83
  background-color: #0c7cd5;
84
  }
 
85
 
 
86
  ''') as demo:
87
  title = gr.HTML('''
88
  <div style="text-align: center;">
 
113
  provideFeedbackBtn = gr.Button("Provide Feedback", elem_id="feedback-btn")
114
 
115
  with gr.Column(visible=False) as feedbackForm:
116
+ ratingRadio = gr.Radio(["1", "2", "3", "4", "5"], label="How would you rate the story")
117
+ feedback_text = gr.Textbox(label='Any other comments?')
118
+ submitFeedbackBtn = gr.Button("Submit Feedback", elem_id="submit-feedback-btn")
119
 
120
  with gr.Column(visible=False) as thankyou:
121
 
122
+ feedback_thankyou = gr.HTML("<h2>Thanks for your feeback!</h2>")
123
 
124
  with gr.Column(visible=False) as mesHistoryCol:
125
 
 
132
  def show_feedback_text():
133
  return {feedbackForm: gr.update(visible=True)}
134
 
135
+ def submitFeedback(comment, rating, character, messageHistory):
136
+
137
+
138
+
139
+ readableHistory = ''
140
+ for m in messageHistory:
141
+ readableHistory += m['content']
142
+ readableHistory += '\n\n'
143
+
144
+ row = [comment, rating, character, readableHistory]
145
+ sheet.append_row(row)
146
+ return {thankyou: gr.update(visible=True), feedbackForm: gr.update(visible=False)}
147
 
148
  def generateStory(character):
149
 
 
177
 
178
  story = response["choices"][0]["message"]["content"]
179
  messageHistory.append(response["choices"][0]["message"])
180
+
181
  return story, messageHistory
182
 
183
  def createNewStory():
 
196
 
197
  provideFeedbackBtn.click(show_feedback_text, [], [feedbackForm])
198
 
199
+ submitFeedbackBtn.click(submitFeedback, [feedback_text, ratingRadio, character, messageHistory], [thankyou, feedbackForm])
200
 
201
  newStoryBtn.click(createNewStory, [], [character, story_output, blank])
202
 
203
 
204
+ demo.launch(debug=True, share=True)