LennardZuendorf commited on
Commit
b6f8496
1 Parent(s): 0f77c21

chore: unifying app and main, finalizing module setup

Browse files
Files changed (4) hide show
  1. app.py +0 -102
  2. explanation/__init__.py +0 -0
  3. main.py +105 -3
  4. memory/__init__.py +0 -0
app.py DELETED
@@ -1,102 +0,0 @@
1
- # main application file initializing the gradio based ui and calling other modules
2
-
3
- # external package imports
4
- import gradio as gr
5
- import markdown
6
-
7
- # internal imports
8
- from model import mistral
9
-
10
- # function to load md files in python as a string
11
- def load_md(path):
12
-
13
- # credit: official python-markdown documentation (https://python-markdown.github.io/reference/)
14
- with open(path, "r") as file:
15
- text = file.read()
16
-
17
- # return markdown as a string
18
- return markdown.markdown(text)
19
-
20
- # ui interface based on Gradio Blocks (see documentation: https://www.gradio.app/docs/interface)
21
- with gr.Blocks() as ui:
22
- # header row with markdown based text
23
- with gr.Row():
24
- gr.Markdown(
25
- """
26
- # Thesis Demo - AI Chat Application with XAI
27
- ### Select between tabs below for the different views.
28
- """)
29
- # ChatBot tab used to chat with the AI chatbot
30
- with gr.Tab("AI ChatBot"):
31
- with gr.Row():
32
- gr.Markdown(
33
- """
34
- ### ChatBot Demo
35
- Mitral AI 7B notebooks fine-tuned for instruction and fully open source (see at [HGF](https://huggingface.co/mistralai/Mistral-7B-v0.1))
36
- """)
37
- # row with chatbot ui displaying "conversation" with the model (see documentation: https://www.gradio.app/docs/chatbot)
38
- with gr.Row():
39
- chatbot = gr.Chatbot(layout="panel", show_copy_button=True,avatar_images=("./public/human.jpg","./public/bot.jpg"))
40
- # disclaimer information row - data is recorded for shap dashboard and model explanability
41
- with gr.Row():
42
- gr.Markdown(
43
- """
44
- ##### ⚠️ All Conversations are recorded for qa assurance and explanation functionality!
45
- """)
46
- # row with input textbox
47
- with gr.Row():
48
- prompt = gr.Textbox(label="Input Message")
49
- # row with columns for buttons to submit and clear content
50
- with gr.Row():
51
- with gr.Column(scale=1):
52
- # default clear button which clearn the given components (see documentation: https://www.gradio.app/docs/clearbutton)
53
- clear_btn = gr.ClearButton([prompt, chatbot])
54
- with gr.Column(scale=1):
55
- submit_btn = gr.Button("Submit")
56
-
57
- # two functions performing the same action (triggered the model response), when the button is used or the textbox submit function is used (clicking enter).
58
- submit_btn.click(mistral.chat, [prompt, chatbot], [prompt, chatbot])
59
- prompt.submit(mistral.chat, [prompt, chatbot], [prompt, chatbot])
60
-
61
- # explanations tab used to provide explanations for a specific conversation
62
- with gr.Tab("Explanations"):
63
- with gr.Row():
64
- gr.Markdown(
65
- """
66
- ### Get Explanations for
67
- SHAP Visualization Dashboard adopted from [shapash](https://github.com/MAIF/shapash)
68
- """)
69
-
70
- # shap dashboard tab for shapash inspired dashboard
71
- with gr.Tab("SHAP Dashboard"):
72
- with gr.Row():
73
- gr.Markdown(
74
- """
75
- ### SHAP Dashboard
76
- SHAP Visualization Dashboard adopted from [shapash](https://github.com/MAIF/shapash)
77
- """)
78
-
79
- # visualize dashboard to display global visualization provided by the BERTViz adoption
80
- with gr.Tab("Visualize Dashboard"):
81
- with gr.Row():
82
- gr.Markdown(
83
- """
84
- ### Visualization Dashboard
85
- Visualization Dashboard adopted from [BERTViz](https://github.com/jessevig/bertviz)
86
- """)
87
-
88
- # model overview tab for transparency
89
- with gr.Tab("notebooks Overview"):
90
- with gr.Tab("Mistral 7B Instruct"):
91
- gr.Markdown(value=load_md("./model/mistral.md"))
92
- with gr.Tab("LlaMa 2 7B Chat"):
93
- gr.Markdown(value=load_md("./model/llama2.md"))
94
-
95
- # final row to show legal information - credits, data protection and link to the LICENSE on GitHub
96
- with gr.Row():
97
- with gr.Accordion("Credits, Data Protection and License", open=False):
98
- gr.Markdown(value=load_md("public/credits_dataprotection_license.md"))
99
-
100
- # launch function for Gradio Interface
101
- if __name__ == "__main__":
102
- ui.launch(share=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
explanation/__init__.py ADDED
File without changes
main.py CHANGED
@@ -1,7 +1,109 @@
1
- from fastapi import FastAPI
 
 
2
  import gradio as gr
3
- import app as gradio_app
 
 
 
 
4
 
 
 
 
 
 
 
 
 
 
 
 
5
  app = FastAPI()
6
 
7
- app = gr.mount_gradio_app(app, gradio_app.ui, path="/")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # main application file initializing the gradio based ui and calling other modules
2
+
3
+ # external package imports
4
  import gradio as gr
5
+ import markdown
6
+ from fastapi import FastAPI
7
+
8
+ # internal imports
9
+ from model import mistral
10
 
11
+ # function to load md files in python as a string
12
+ def load_md(path):
13
+
14
+ # credit: official python-markdown documentation (https://python-markdown.github.io/reference/)
15
+ with open(path, "r") as file:
16
+ text = file.read()
17
+
18
+ # return markdown as a string
19
+ return markdown.markdown(text)
20
+
21
+ # creation of FastAPI application
22
  app = FastAPI()
23
 
24
+ # ui interface based on Gradio Blocks (see documentation: https://www.gradio.app/docs/interface)
25
+ with gr.Blocks() as ui:
26
+ # header row with markdown based text
27
+ with gr.Row():
28
+ gr.Markdown(
29
+ """
30
+ # Thesis Demo - AI Chat Application with XAI
31
+ ### Select between tabs below for the different views.
32
+ """)
33
+ # ChatBot tab used to chat with the AI chatbot
34
+ with gr.Tab("AI ChatBot"):
35
+ with gr.Row():
36
+ gr.Markdown(
37
+ """
38
+ ### ChatBot Demo
39
+ Mitral AI 7B notebooks fine-tuned for instruction and fully open source (see at [HGF](https://huggingface.co/mistralai/Mistral-7B-v0.1))
40
+ """)
41
+ # row with chatbot ui displaying "conversation" with the model (see documentation: https://www.gradio.app/docs/chatbot)
42
+ with gr.Row():
43
+ chatbot = gr.Chatbot(layout="panel", show_copy_button=True,avatar_images=("./public/human.jpg","./public/bot.jpg"))
44
+ # disclaimer information row - data is recorded for shap dashboard and model explanability
45
+ with gr.Row():
46
+ gr.Markdown(
47
+ """
48
+ ##### ⚠️ All Conversations are recorded for qa assurance and explanation functionality!
49
+ """)
50
+ # row with input textbox
51
+ with gr.Row():
52
+ prompt = gr.Textbox(label="Input Message")
53
+ # row with columns for buttons to submit and clear content
54
+ with gr.Row():
55
+ with gr.Column(scale=1):
56
+ # default clear button which clearn the given components (see documentation: https://www.gradio.app/docs/clearbutton)
57
+ clear_btn = gr.ClearButton([prompt, chatbot])
58
+ with gr.Column(scale=1):
59
+ submit_btn = gr.Button("Submit")
60
+
61
+ # two functions performing the same action (triggered the model response), when the button is used or the textbox submit function is used (clicking enter).
62
+ submit_btn.click(mistral.chat, [prompt, chatbot], [prompt, chatbot])
63
+ prompt.submit(mistral.chat, [prompt, chatbot], [prompt, chatbot])
64
+
65
+ # explanations tab used to provide explanations for a specific conversation
66
+ with gr.Tab("Explanations"):
67
+ with gr.Row():
68
+ gr.Markdown(
69
+ """
70
+ ### Get Explanations for
71
+ SHAP Visualization Dashboard adopted from [shapash](https://github.com/MAIF/shapash)
72
+ """)
73
+
74
+ # shap dashboard tab for shapash inspired dashboard
75
+ with gr.Tab("SHAP Dashboard"):
76
+ with gr.Row():
77
+ gr.Markdown(
78
+ """
79
+ ### SHAP Dashboard
80
+ SHAP Visualization Dashboard adopted from [shapash](https://github.com/MAIF/shapash)
81
+ """)
82
+
83
+ # visualize dashboard to display global visualization provided by the BERTViz adoption
84
+ with gr.Tab("Visualize Dashboard"):
85
+ with gr.Row():
86
+ gr.Markdown(
87
+ """
88
+ ### Visualization Dashboard
89
+ Visualization Dashboard adopted from [BERTViz](https://github.com/jessevig/bertviz)
90
+ """)
91
+
92
+ # model overview tab for transparency
93
+ with gr.Tab("notebooks Overview"):
94
+ with gr.Tab("Mistral 7B Instruct"):
95
+ gr.Markdown(value=load_md("./model/mistral.md"))
96
+ with gr.Tab("LlaMa 2 7B Chat"):
97
+ gr.Markdown(value=load_md("./model/llama2.md"))
98
+
99
+ # final row to show legal information - credits, data protection and link to the LICENSE on GitHub
100
+ with gr.Row():
101
+ with gr.Accordion("Credits, Data Protection and License", open=False):
102
+ gr.Markdown(value=load_md("public/credits_dataprotection_license.md"))
103
+
104
+ # launch function for fastAPI Application
105
+ app = gr.mount_gradio_app(app, ui, path="/")
106
+
107
+ # launch function for Gradio Interface on hgf spaces
108
+ if __name__ == "__main__":
109
+ ui.launch(share=False)
memory/__init__.py ADDED
File without changes