Spaces:
Runtime error
Runtime error
prathameshdalal
commited on
Commit
•
5d927cd
1
Parent(s):
a095a73
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def companyChat(company_name, chat_history):
|
4 |
+
from langchain.chains import ConversationalRetrievalChain
|
5 |
+
from langchain_community.retrievers import KayAiRetriever
|
6 |
+
from langchain_anthropic import ChatAnthropic
|
7 |
+
model = ChatAnthropic(
|
8 |
+
model_name="claude-3-sonnet-20240229"
|
9 |
+
)
|
10 |
+
retriever = KayAiRetriever.create(
|
11 |
+
dataset_id="company", data_types=["10-K"], num_contexts=10
|
12 |
+
)
|
13 |
+
qa = ConversationalRetrievalChain.from_llm(model, retriever=retriever)
|
14 |
+
company = company_name
|
15 |
+
outputs = []
|
16 |
+
chat_history = []
|
17 |
+
questions = [
|
18 |
+
f"Summarize the {company}'s financial performance over the past years, including revenue growth, profitability (net income), and margins.",
|
19 |
+
f"Identify and analyze {company}'s earnings per share (EPS diluted and basic), Calculate Return on equity (ROE) and Debt-to-Equity ratio For past few years",
|
20 |
+
f"Add bullet points for main risks identified by {company} in its 10-K filing" ]
|
21 |
+
for question in questions:
|
22 |
+
result = qa({"question": question, "chat_history": chat_history})
|
23 |
+
chat_history.append((question, result["answer"]))
|
24 |
+
outputs.append(result["answer"]) # Append both answers to a list
|
25 |
+
return outputs # Return the list of both answers
|
26 |
+
|
27 |
+
# Define the interface with inputs and outputs
|
28 |
+
interface = gr.Interface(
|
29 |
+
fn=companyChat,
|
30 |
+
inputs=gr.Textbox(label="Company Name or Ticker"),
|
31 |
+
outputs=[gr.Textbox(label="Company's financial performance over the past years"), gr.Textbox(label="Company's earnings per share (EPS), return on equity (ROE), and debt-to-equity ratio For past few years"), gr.Textbox(label="Main risks identified in 10-K filing")],
|
32 |
+
title="Insights on 10K Filings",
|
33 |
+
description="Get Insights right from the 10K Filings submitted by the company",
|
34 |
+
theme="soft",
|
35 |
+
examples=["APPL"],
|
36 |
+
cache_examples=True,
|
37 |
+
clear_btn="Clear",
|
38 |
+
)
|
39 |
+
|
40 |
+
interface.launch()
|