yelboudouri commited on
Commit
3ed603a
·
1 Parent(s): dd1d834

Initial Commit

Browse files
Files changed (2) hide show
  1. app.py +222 -0
  2. requirements.py +1 -0
app.py ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import gradio as gr
4
+ import requests
5
+
6
+
7
+ def fetch_character():
8
+ response = requests.post(f"{os.getenv('BACK_URL')}/get-story")
9
+
10
+ if response.status_code == 200:
11
+ data = response.json()
12
+
13
+ return (
14
+ data["character"]["id"],
15
+ data["character"]["description"],
16
+ data["scenario_one"]["id"],
17
+ data["scenario_one"]["interaction"],
18
+ data["scenario_two"]["id"],
19
+ data["scenario_two"]["interaction"],
20
+ )
21
+
22
+
23
+ def send(
24
+ char_id,
25
+ scena_one_id,
26
+ emotion,
27
+ response_one,
28
+ scena_two_id,
29
+ decision,
30
+ response_two,
31
+ likes_button,
32
+ ):
33
+ payload = {
34
+ "character_id": char_id,
35
+ "scenario_one_id": scena_one_id,
36
+ "emotion": emotion,
37
+ "response_one": response_one,
38
+ "scenario_two_id": scena_two_id,
39
+ "decision": decision,
40
+ "response_two": response_two,
41
+ "like_dislike": likes_button,
42
+ }
43
+ requests.post(f"{os.getenv('BACK_URL')}/store-response", json=payload)
44
+
45
+ return fetch_character()
46
+
47
+
48
+ css = """
49
+ .gradio-container {
50
+ max-width: 780px !important;
51
+ }
52
+
53
+ .indent > div {
54
+ margin-left: 20px;
55
+ }
56
+ .indent_row > div:first-child {
57
+ margin-left: 20px;
58
+ }
59
+
60
+ .center-content {
61
+ display: flex;
62
+ justify-content: center;
63
+ align-items: center;
64
+ width: 100%; /* Ensure the row/block takes full width */
65
+ }
66
+
67
+ #radio-row {
68
+ display: flex;
69
+ justify-content: center;
70
+ align-items: center;
71
+ width: 100%;
72
+ flex-grow: 1;
73
+ }
74
+
75
+ #radio-row fieldset {
76
+ margin: 0 auto;
77
+ display: flex;
78
+ justify-content: center;
79
+ min-width: auto;
80
+ }
81
+ """
82
+
83
+ with gr.Blocks(css=css) as app:
84
+ new_character = fetch_character()
85
+ character_id = gr.State(new_character[0])
86
+ character_description = gr.State(new_character[1])
87
+ scenario_one_id = gr.State(new_character[2])
88
+ emotion_scenario = gr.State(new_character[3])
89
+ scenario_two_id = gr.State(new_character[4])
90
+ decision_scenario = gr.State(new_character[5])
91
+
92
+ with gr.Row():
93
+ gr.Markdown('<h1 style="text-align: center;">RPEval</h1><p>LLMs have a great potential at '
94
+ 'roleplaying, but which one stands out as the best? This project aims to evaluate '
95
+ 'the roleplaying capabilities of various LLMs.</p><p>To contribute to this project, '
96
+ 'please read the role provided below and respond to the two scenarios while fully '
97
+ 'embodying the assigned character. The character can be anything—from a human or '
98
+ 'elf to a robot or something entirely unique. Thank you for your participation and support! ❤️</p>')
99
+
100
+ @gr.render(inputs=[character_description, emotion_scenario, decision_scenario])
101
+ def render_character(description, emo_scenario, dec_scenario):
102
+ gr.Markdown(description, container=True)
103
+ with gr.Row(elem_id="radio-row"):
104
+ likes_button = gr.Radio(["Like", "Dislike"], container=False)
105
+
106
+ with gr.Column(variant="compact"):
107
+ gr.Markdown("**Another character:**")
108
+ gr.Markdown(
109
+ emo_scenario,
110
+ elem_classes="indent",
111
+ )
112
+ gr.Markdown("**Your response:**")
113
+ with gr.Row(elem_classes="indent_row"):
114
+ emotion = gr.Dropdown(
115
+ [
116
+ "Choose your emotion..",
117
+ "Anger",
118
+ "Anticipation",
119
+ "Determination",
120
+ "Disgust",
121
+ "Excitement",
122
+ "Fear",
123
+ "Guilt",
124
+ "Hope",
125
+ "Joy",
126
+ "Love",
127
+ "Pride",
128
+ "Sadness",
129
+ "Surprise",
130
+ ],
131
+ label="",
132
+ scale=2,
133
+ container=False,
134
+ )
135
+ response_one = gr.Textbox(
136
+ label="", scale=4, container=False, placeholder="Your response.."
137
+ )
138
+
139
+ with gr.Column(variant="compact"):
140
+ gr.Markdown("**Yet another character:**")
141
+ gr.Markdown(
142
+ dec_scenario,
143
+ elem_classes="indent",
144
+ )
145
+ gr.Markdown("**Your response:**")
146
+ with gr.Row(elem_classes="indent_row"):
147
+ decision = gr.Dropdown(
148
+ ["Choose your decision..", "Yes", "No"],
149
+ label="",
150
+ scale=2,
151
+ container=False,
152
+ )
153
+ response_two = gr.Textbox(
154
+ label="", scale=4, container=False, placeholder="Your response.."
155
+ )
156
+
157
+ with gr.Row():
158
+ new_button = gr.Button(value="New Character")
159
+ send_button = gr.Button(value="Send", interactive=False)
160
+
161
+ def validate_inputs(emotion_value, decision_value):
162
+ if (
163
+ emotion_value != "Choose your emotion.."
164
+ or decision_value != "Choose your decision.."
165
+ ):
166
+ return gr.update(interactive=True)
167
+ return gr.update(interactive=False)
168
+
169
+ emotion.change(
170
+ validate_inputs,
171
+ inputs=[emotion, decision],
172
+ outputs=send_button,
173
+ )
174
+ decision.change(
175
+ validate_inputs,
176
+ inputs=[emotion, decision],
177
+ outputs=send_button,
178
+ )
179
+
180
+ send_button.click(
181
+ fn=send,
182
+ inputs=[
183
+ character_id,
184
+ scenario_one_id,
185
+ emotion,
186
+ response_one,
187
+ scenario_two_id,
188
+ decision,
189
+ response_two,
190
+ likes_button,
191
+ ],
192
+ outputs=[
193
+ character_id,
194
+ character_description,
195
+ scenario_one_id,
196
+ emotion_scenario,
197
+ scenario_two_id,
198
+ decision_scenario,
199
+ ],
200
+ )
201
+
202
+ new_button.click(
203
+ fn=fetch_character,
204
+ outputs=[
205
+ character_id,
206
+ character_description,
207
+ scenario_one_id,
208
+ emotion_scenario,
209
+ scenario_two_id,
210
+ decision_scenario,
211
+ ],
212
+ )
213
+
214
+ gr.Markdown(
215
+ "<p>* You need to select an emotion or a decision to send your responses.</p>"
216
+ "<p>** The collected data will be used for research purposes.</p>",
217
+ container=False,
218
+ )
219
+
220
+
221
+ if __name__ == "__main__":
222
+ app.launch()
requirements.py ADDED
@@ -0,0 +1 @@
 
 
1
+ requests