Charreau Bell, Ph.D commited on
Commit
a992ccc
1 Parent(s): f1c7f41

Merge pull request #201 from vanderbilt-data-science/189-prompt-fix

Browse files
Files changed (3) hide show
  1. Dockerfile +1 -1
  2. app.py +9 -87
  3. requirements.txt +4 -2
Dockerfile CHANGED
@@ -30,4 +30,4 @@ WORKDIR $HOME/app
30
  # Copy the current directory contents into the container at $HOME/app setting the owner to the user
31
  COPY --chown=user . $HOME/app
32
 
33
- CMD ["python", "app.py"]
 
30
  # Copy the current directory contents into the container at $HOME/app setting the owner to the user
31
  COPY --chown=user . $HOME/app
32
 
33
+ CMD ["python", "app.py"]
app.py CHANGED
@@ -1,89 +1,11 @@
1
- import os
2
- import gradio as gr
3
- import pandas as pd
4
- from functools import partial
5
- from ai_classroom_suite.UIBaseComponents import *
6
-
7
- ### User Interface Chatbot Functions ###
8
- def get_tutor_reply(chat_tutor):
9
- chat_tutor.get_tutor_reply()
10
- return gr.update(value="", interactive=True), chat_tutor.conversation_memory, chat_tutor
11
-
12
- def get_conversation_history(chat_tutor):
13
- return chat_tutor.conversation_memory, chat_tutor
14
-
15
- ### User Interfaces ###
16
- with gr.Blocks() as demo:
17
- #initialize tutor (with state)
18
- study_tutor = gr.State(SlightlyDelusionalTutor())
19
-
20
- # Student chatbot interface
21
- gr.Markdown("""
22
- ## Chat with the Model
23
- Description here
24
- """)
25
-
26
- """
27
- API Authentication functionality
28
- Instead of ask students to provide key, the key is now provided by the instructor.
29
- To permanently set the key, go to Settings -> Variables and secrets -> Secrets,
30
- then replace OPENAI_API_KEY value with whatever openai key of the instructor.
31
- """
32
- api_input = gr.Textbox(show_label=False, type="password", visible=False, value=os.environ.get("OPENAI_API_KEY"))
33
 
34
- # The instructor will provide a secret prompt/persona to the tutor
35
- instructor_prompt = gr.Textbox(label="Verify your prompt content", value = os.environ.get("SECRET_PROMPT"), visible=False)
36
-
37
- # Placeholders components
38
- text_input_none = gr.Textbox(visible=False)
39
- file_input_none = gr.File(visible=False)
40
- instructor_input_none = gr.TextArea(visible=False)
41
- learning_objectives_none = gr.Textbox(visible=False)
42
-
43
- # Set the secret prompt in this session and embed it to the study tutor
44
- prompt_submit_btn = gr.Button("Initialize Tutor")
45
- prompt_submit_btn.click(
46
- fn=create_reference_store,
47
- inputs=[study_tutor, prompt_submit_btn, instructor_prompt, file_input_none, instructor_input_none, api_input, instructor_prompt],
48
- outputs=[study_tutor, prompt_submit_btn]
49
- )
50
-
51
- with gr.Row(equal_height=True):
52
- with gr.Column(scale=2):
53
- chatbot = gr.Chatbot()
54
- with gr.Row():
55
- user_chat_input = gr.Textbox(label="User input", scale=9)
56
- user_chat_submit = gr.Button("Ask/answer model", scale=1)
57
-
58
- # First add user's message to the conversation history
59
- # Then get reply from the tutor and add that to the conversation history
60
- user_chat_submit.click(
61
- fn = add_user_message, inputs = [user_chat_input, study_tutor], outputs = [user_chat_input, chatbot, study_tutor], queue=False
62
- ).then(
63
- fn = get_tutor_reply, inputs = [study_tutor], outputs = [user_chat_input, chatbot, study_tutor], queue=True
64
- )
65
-
66
- # Testing the chat history storage, can be deleted at deployment
67
- with gr.Blocks():
68
- test_btn = gr.Button("View your chat history")
69
- chat_history = gr.JSON(label = "conversation history")
70
- test_btn.click(get_conversation_history, inputs=[study_tutor], outputs=[chat_history, study_tutor])
71
 
72
- # Download conversation history file
73
- with gr.Blocks():
74
- gr.Markdown("""
75
- ## Export Your Chat History
76
- Export your chat history as a .json, .txt, or .csv file
77
- """)
78
- with gr.Row():
79
- export_dialogue_button_json = gr.Button("JSON")
80
- export_dialogue_button_txt = gr.Button("TXT")
81
- export_dialogue_button_csv = gr.Button("CSV")
82
-
83
- file_download = gr.Files(label="Download here", file_types=['.json', '.txt', '.csv'], type="file", visible=False)
84
-
85
- export_dialogue_button_json.click(save_json, study_tutor, file_download, show_progress=True)
86
- export_dialogue_button_txt.click(save_txt, study_tutor, file_download, show_progress=True)
87
- export_dialogue_button_csv.click(save_csv, study_tutor, file_download, show_progress=True)
88
-
89
- demo.queue().launch(server_name='0.0.0.0', server_port=7860)
 
1
+ ###Autogenerated code from internal Makefile
2
+ ### Sourced from file: Apps/ui_nbs/BasicInteractionApp.ipynb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
+ #| to_script
5
+ # Import the needed components
6
+ from ai_classroom_suite.UIBaseComponents import *
7
+ from ai_classroom_suite.BasicInteraction import *
8
+ from ai_classroom_suite.BasicInteraction import BasicInteractionDemo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ # Launch the relevant component
11
+ BasicInteractionDemo.queue().launch(server_name='0.0.0.0', server_port=7860, show_error=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -2,7 +2,9 @@ langchain
2
  pandas
3
  numpy
4
  openai
5
- gradio
6
  chromadb
7
  tiktoken
8
- unstructured
 
 
 
2
  pandas
3
  numpy
4
  openai
5
+ gradio>3.5,<4.0
6
  chromadb
7
  tiktoken
8
+ unstructured
9
+ poppler-utils
10
+ unstructured[pdf]