Spaces:
Build error
Build error
Commit
Β·
dac5204
1
Parent(s):
0be388c
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
from functools import partial
|
@@ -6,12 +7,7 @@ from ai_classroom_suite.UIBaseComponents import *
|
|
6 |
# history is a list of list
|
7 |
# [[user_input_str, bot_response_str], ...]
|
8 |
|
9 |
-
class EchoingTutor:
|
10 |
-
# create basic initialization function
|
11 |
-
def __init__(self):
|
12 |
-
self.conversation_memory = []
|
13 |
-
self.flattened_conversation = ''
|
14 |
-
|
15 |
def add_user_message(self, user_message):
|
16 |
self.conversation_memory.append([user_message, None])
|
17 |
self.flattened_conversation = self.flattened_conversation + '\n\n' + 'User: ' + user_message
|
@@ -40,38 +36,16 @@ def get_tutor_reply(user_message, chat_tutor):
|
|
40 |
|
41 |
def get_conversation_history(chat_tutor):
|
42 |
return chat_tutor.conversation_memory, chat_tutor
|
|
|
43 |
|
44 |
-
|
45 |
-
css="""
|
46 |
-
#sources-container {
|
47 |
-
overflow: scroll !important; /* Needs to override default formatting */
|
48 |
-
/*max-height: 20em; */ /* Arbitrary value */
|
49 |
-
}
|
50 |
-
#sources-container > div { padding-bottom: 1em !important; /* Arbitrary value */ }
|
51 |
-
.short-height > * > * { min-height: 0 !important; }
|
52 |
-
.translucent { opacity: 0.5; }
|
53 |
-
.textbox_label { padding-bottom: .5em; }
|
54 |
-
"""
|
55 |
-
|
56 |
-
with gr.Blocks(css=css) as demo:
|
57 |
#initialize tutor (with state)
|
58 |
study_tutor = gr.State(EchoingTutor())
|
59 |
|
60 |
-
#
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
with gr.Box():
|
65 |
-
gr.Markdown("### OpenAI API Key ")
|
66 |
-
gr.HTML("""<span>Embed your OpenAI API key below; if you haven't created one already, visit
|
67 |
-
<a href="https://platform.openai.com/account/api-keys">platform.openai.com/account/api-keys</a>
|
68 |
-
to sign up for an account and get your personal API key</span>""",
|
69 |
-
elem_classes="textbox_label")
|
70 |
-
api_input = gr.Textbox(show_label=False, type="password", container=False, autofocus=True,
|
71 |
-
placeholder="βββββββββββββββββ", value='')
|
72 |
-
api_input.submit(fn=embed_key, inputs=[api_input, study_tutor], outputs=study_tutor)
|
73 |
-
api_input.blur(fn=embed_key, inputs=[api_input, study_tutor], outputs=study_tutor)
|
74 |
-
|
75 |
# Chatbot interface
|
76 |
gr.Markdown("""
|
77 |
## Chat with the Model
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
import pandas as pd
|
4 |
from functools import partial
|
|
|
7 |
# history is a list of list
|
8 |
# [[user_input_str, bot_response_str], ...]
|
9 |
|
10 |
+
class EchoingTutor(SlightlyDelusionalTutor):
|
|
|
|
|
|
|
|
|
|
|
11 |
def add_user_message(self, user_message):
|
12 |
self.conversation_memory.append([user_message, None])
|
13 |
self.flattened_conversation = self.flattened_conversation + '\n\n' + 'User: ' + user_message
|
|
|
36 |
|
37 |
def get_conversation_history(chat_tutor):
|
38 |
return chat_tutor.conversation_memory, chat_tutor
|
39 |
+
|
40 |
|
41 |
+
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
#initialize tutor (with state)
|
43 |
study_tutor = gr.State(EchoingTutor())
|
44 |
|
45 |
+
# API Authentication
|
46 |
+
# Instead of ask students to provide key, the key is now directly provided by the instructor
|
47 |
+
embed_key(os.environ.get("OPENAI_API_KEY"), study_tutor)
|
48 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
# Chatbot interface
|
50 |
gr.Markdown("""
|
51 |
## Chat with the Model
|