feat: update app
Browse files
app.py
CHANGED
@@ -50,7 +50,7 @@ class MdnaQA:
|
|
50 |
|
51 |
|
52 |
|
53 |
-
filename =
|
54 |
loader = TextLoader(filename)
|
55 |
documents = loader.load()
|
56 |
model_name = "text-davinci-003"
|
@@ -62,50 +62,73 @@ title = "Alphabet's Q1 2023 10-Q MD&A"
|
|
62 |
video = '<iframe width="560" height="315" src="https://www.youtube.com/embed/mI6_SF3bYJs" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>'
|
63 |
|
64 |
with gr.Blocks(title=title) as demo:
|
65 |
-
gr.Markdown(f
|
66 |
# gr.HTML(video)
|
67 |
-
gr.Markdown(
|
68 |
-
gr.Markdown(
|
|
|
|
|
69 |
openai_api_key = gr.Text(
|
70 |
value=os.getenv("OPENAI_API_KEY"),
|
71 |
type="password",
|
72 |
label="OpenAI API key",
|
73 |
)
|
74 |
-
temperature = gr.Slider(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
mdna = gr.State(docs)
|
76 |
-
tokens_total = gr.Textbox(
|
|
|
|
|
|
|
|
|
77 |
with gr.Tabs(visible=True) as tabs:
|
78 |
with gr.TabItem("Summary"):
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
82 |
|
83 |
def summarize_mdna(docs, api_key, temp):
|
84 |
llm = OpenAI(temperature=temp, openai_api_key=api_key)
|
85 |
mdna_summary = summarize_docs(llm, docs)
|
86 |
return mdna_summary
|
87 |
|
88 |
-
summarize.click(
|
|
|
|
|
|
|
|
|
89 |
with gr.TabItem("QA with MD&A"):
|
90 |
-
start_qa = gr.Button("Start QA with MD&A", variant=
|
91 |
chatbot = gr.Chatbot(label="QA with MD&A", visible=False)
|
92 |
question = gr.Textbox(
|
93 |
label="Your question", interactive=True, visible=False
|
94 |
)
|
95 |
qa_chat = gr.State()
|
96 |
-
send = gr.Button("Ask question", variant=
|
97 |
|
98 |
-
def start_chat(docs,
|
99 |
-
|
|
|
100 |
return (
|
101 |
qa_chat,
|
102 |
gr.Textbox.update(visible=True),
|
103 |
gr.Textbox.update(visible=True),
|
104 |
-
gr.Button.update(visible=True)
|
105 |
)
|
106 |
|
107 |
start_qa.click(
|
108 |
-
start_chat,
|
|
|
|
|
109 |
)
|
110 |
|
111 |
def respond(qa_chat, question, chat_history):
|
@@ -114,9 +137,7 @@ with gr.Blocks(title=title) as demo:
|
|
114 |
return "", chat_history
|
115 |
|
116 |
send.click(respond, [qa_chat, question, chatbot], [question, chatbot])
|
117 |
-
question.submit(
|
118 |
-
respond, [qa_chat, question, chatbot], [question, chatbot]
|
119 |
-
)
|
120 |
|
121 |
|
122 |
demo.launch()
|
|
|
50 |
|
51 |
|
52 |
|
53 |
+
filename = "2023-05-12_2023_q1_goog_mdna.txt"
|
54 |
loader = TextLoader(filename)
|
55 |
documents = loader.load()
|
56 |
model_name = "text-davinci-003"
|
|
|
62 |
video = '<iframe width="560" height="315" src="https://www.youtube.com/embed/mI6_SF3bYJs" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>'
|
63 |
|
64 |
with gr.Blocks(title=title) as demo:
|
65 |
+
gr.Markdown(f"# {title}")
|
66 |
# gr.HTML(video)
|
67 |
+
gr.Markdown("Blog post https://blog.experienced.dev")
|
68 |
+
gr.Markdown(
|
69 |
+
"You can get an API key [from OpenAI](https://platform.openai.com/account/api-keys)"
|
70 |
+
)
|
71 |
openai_api_key = gr.Text(
|
72 |
value=os.getenv("OPENAI_API_KEY"),
|
73 |
type="password",
|
74 |
label="OpenAI API key",
|
75 |
)
|
76 |
+
temperature = gr.Slider(
|
77 |
+
0,
|
78 |
+
2,
|
79 |
+
value=0,
|
80 |
+
step=0.1,
|
81 |
+
label="Temperature",
|
82 |
+
info="adjusts a model's output from predictable to random",
|
83 |
+
)
|
84 |
mdna = gr.State(docs)
|
85 |
+
tokens_total = gr.Textbox(
|
86 |
+
label="Total input tokens",
|
87 |
+
value=tokens_sum,
|
88 |
+
info="how many tokens will be spent on input / embeddings",
|
89 |
+
)
|
90 |
with gr.Tabs(visible=True) as tabs:
|
91 |
with gr.TabItem("Summary"):
|
92 |
+
summarize = gr.Button(
|
93 |
+
"Summarize MD&A",
|
94 |
+
variant="primary",
|
95 |
+
info="On click you spent tokens on input, instructions and output",
|
96 |
+
)
|
97 |
+
summary = gr.TextArea(label="Summary")
|
98 |
|
99 |
def summarize_mdna(docs, api_key, temp):
|
100 |
llm = OpenAI(temperature=temp, openai_api_key=api_key)
|
101 |
mdna_summary = summarize_docs(llm, docs)
|
102 |
return mdna_summary
|
103 |
|
104 |
+
summarize.click(
|
105 |
+
summarize_mdna,
|
106 |
+
inputs=[mdna, openai_api_key, temperature],
|
107 |
+
outputs=[summary],
|
108 |
+
)
|
109 |
with gr.TabItem("QA with MD&A"):
|
110 |
+
start_qa = gr.Button("Start QA with MD&A", variant="primary")
|
111 |
chatbot = gr.Chatbot(label="QA with MD&A", visible=False)
|
112 |
question = gr.Textbox(
|
113 |
label="Your question", interactive=True, visible=False
|
114 |
)
|
115 |
qa_chat = gr.State()
|
116 |
+
send = gr.Button("Ask question", variant="primary", visible=False)
|
117 |
|
118 |
+
def start_chat(docs, api_key, temp):
|
119 |
+
llm = OpenAI(temperature=temp, openai_api_key=api_key)
|
120 |
+
qa_chat = MdnaQA(llm, docs)
|
121 |
return (
|
122 |
qa_chat,
|
123 |
gr.Textbox.update(visible=True),
|
124 |
gr.Textbox.update(visible=True),
|
125 |
+
gr.Button.update(visible=True),
|
126 |
)
|
127 |
|
128 |
start_qa.click(
|
129 |
+
start_chat,
|
130 |
+
[mdna, openai_api_key, temperature],
|
131 |
+
[qa_chat, chatbot, question, send],
|
132 |
)
|
133 |
|
134 |
def respond(qa_chat, question, chat_history):
|
|
|
137 |
return "", chat_history
|
138 |
|
139 |
send.click(respond, [qa_chat, question, chatbot], [question, chatbot])
|
140 |
+
question.submit(respond, [qa_chat, question, chatbot], [question, chatbot])
|
|
|
|
|
141 |
|
142 |
|
143 |
demo.launch()
|