feat: update app
Browse files
app.py
CHANGED
@@ -49,6 +49,7 @@ class MdnaQA:
|
|
49 |
return self.chain.run(input_documents=input_documents, question=question)
|
50 |
|
51 |
|
|
|
52 |
filename = '2023-05-12_2023_q1_goog_mdna.txt'
|
53 |
loader = TextLoader(filename)
|
54 |
documents = loader.load()
|
@@ -58,12 +59,13 @@ docs = split_documents(documents, tiktoken_len)
|
|
58 |
tokens_sum = sum(tiktoken_len(d.page_content) for d in docs)
|
59 |
|
60 |
title = "Alphabet's Q1 2023 10-Q MD&A"
|
|
|
61 |
|
62 |
with gr.Blocks(title=title) as demo:
|
63 |
gr.Markdown(f'# {title}')
|
64 |
-
gr.
|
65 |
-
gr.Markdown('
|
66 |
-
gr.Markdown("You can an API key [from OpenAI](https://platform.openai.com/account/api-keys)")
|
67 |
openai_api_key = gr.Text(
|
68 |
value=os.getenv("OPENAI_API_KEY"),
|
69 |
type="password",
|
@@ -80,8 +82,8 @@ with gr.Blocks(title=title) as demo:
|
|
80 |
|
81 |
def summarize_mdna(docs, api_key, temp):
|
82 |
llm = OpenAI(temperature=temp, openai_api_key=api_key)
|
83 |
-
|
84 |
-
return
|
85 |
|
86 |
summarize.click(summarize_mdna, inputs=[mdna, openai_api_key, temperature], outputs=[summary])
|
87 |
with gr.TabItem("QA with MD&A"):
|
@@ -94,8 +96,7 @@ with gr.Blocks(title=title) as demo:
|
|
94 |
send = gr.Button("Ask question", variant='primary', visible=False)
|
95 |
|
96 |
def start_chat(docs, openai_api_key):
|
97 |
-
|
98 |
-
qa_chat = MDNAQAMock()
|
99 |
return (
|
100 |
qa_chat,
|
101 |
gr.Textbox.update(visible=True),
|
@@ -110,7 +111,6 @@ with gr.Blocks(title=title) as demo:
|
|
110 |
def respond(qa_chat, question, chat_history):
|
111 |
answer = qa_chat.ask(question)
|
112 |
chat_history.append((question, answer))
|
113 |
-
time.sleep(3)
|
114 |
return "", chat_history
|
115 |
|
116 |
send.click(respond, [qa_chat, question, chatbot], [question, chatbot])
|
|
|
49 |
return self.chain.run(input_documents=input_documents, question=question)
|
50 |
|
51 |
|
52 |
+
|
53 |
filename = '2023-05-12_2023_q1_goog_mdna.txt'
|
54 |
loader = TextLoader(filename)
|
55 |
documents = loader.load()
|
|
|
59 |
tokens_sum = sum(tiktoken_len(d.page_content) for d in docs)
|
60 |
|
61 |
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'# {title}')
|
66 |
+
# gr.HTML(video)
|
67 |
+
gr.Markdown('Blog post https://blog.experienced.dev')
|
68 |
+
gr.Markdown("You can get an API key [from OpenAI](https://platform.openai.com/account/api-keys)")
|
69 |
openai_api_key = gr.Text(
|
70 |
value=os.getenv("OPENAI_API_KEY"),
|
71 |
type="password",
|
|
|
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(summarize_mdna, inputs=[mdna, openai_api_key, temperature], outputs=[summary])
|
89 |
with gr.TabItem("QA with MD&A"):
|
|
|
96 |
send = gr.Button("Ask question", variant='primary', visible=False)
|
97 |
|
98 |
def start_chat(docs, openai_api_key):
|
99 |
+
qa_chat = MdnaQA(docs, openai_api_key)
|
|
|
100 |
return (
|
101 |
qa_chat,
|
102 |
gr.Textbox.update(visible=True),
|
|
|
111 |
def respond(qa_chat, question, chat_history):
|
112 |
answer = qa_chat.ask(question)
|
113 |
chat_history.append((question, answer))
|
|
|
114 |
return "", chat_history
|
115 |
|
116 |
send.click(respond, [qa_chat, question, chatbot], [question, chatbot])
|