mlara commited on
Commit
79c15a9
·
1 Parent(s): adb0852

first commit

Browse files
Files changed (37) hide show
  1. Dockerfile +11 -0
  2. EarningsTranscripts (PDF)/AAPL/Apple (AAPL) Q2 2023 Earnings Call Transcript.pdf +0 -0
  3. EarningsTranscripts (PDF)/AAPL/Apple Inc. (AAPL) CEO Tim Cook on Q1 2022 Results - Earnings Call Transcript.pdf +0 -0
  4. EarningsTranscripts (PDF)/AAPL/Apple Inc. (AAPL) CEO Tim Cook on Q2 2022 Results - Earnings Call Transcript.pdf +0 -0
  5. EarningsTranscripts (PDF)/AAPL/Apple Inc. (AAPL) Q3 2023 Earnings Call Transcript.pdf +0 -0
  6. EarningsTranscripts (PDF)/AAPL/Apple Inc. (AAPL) Q4 2022 Earnings Call Transcript.pdf +0 -0
  7. EarningsTranscripts (PDF)/AAPL/Apple Inc. (AAPL) Q4 2023 Earnings Call Transcript.pdf +0 -0
  8. EarningsTranscripts (PDF)/AAPL/Apple, Inc. (AAPL) CEO Tim Cook on Q3 2022 Results - Earnings Call Transcript.pdf +0 -0
  9. EarningsTranscripts (PDF)/AAPL/Apple, Inc. (AAPL) Q1 2023 Earnings Call Transcript.pdf +0 -0
  10. EarningsTranscripts (PDF)/GOOG/Alphabet Inc. (GOOG) CEO Sundar Pichai on Q2 2022 Results - Earnings Call Transcript.pdf +0 -0
  11. EarningsTranscripts (PDF)/GOOG/Alphabet Inc. (GOOG) Q1 2023 Earnings Call Transcript.pdf +0 -0
  12. EarningsTranscripts (PDF)/GOOG/Alphabet Inc. (GOOG) Q2 2023 Earnings Call Transcript.pdf +0 -0
  13. EarningsTranscripts (PDF)/GOOG/Alphabet Inc. (GOOG) Q3 2022 Earnings Call Transcript.pdf +0 -0
  14. EarningsTranscripts (PDF)/GOOG/Alphabet Inc. (GOOG) Q3 2023 Earnings Call Transcript.pdf +0 -0
  15. EarningsTranscripts (PDF)/GOOG/Alphabet Inc. (GOOG) Q4 2022 Earnings Call Transcript.pdf +0 -0
  16. EarningsTranscripts (PDF)/GOOG/Alphabet Inc.'s (GOOG) CEO Sundar Pichai on Q1 2022 Results - Earnings Call Transcript.pdf +0 -0
  17. EarningsTranscripts (PDF)/MSFT/Microsoft Corporation (MSFT) CEO Satya Nadella on Q1 Fiscal 2022 Results - Earnings Call Transcript.pdf +0 -0
  18. EarningsTranscripts (PDF)/MSFT/Microsoft Corporation (MSFT) CEO Satya Nadella on Q4 2022 Results - Earnings Call Transcript.pdf +0 -0
  19. EarningsTranscripts (PDF)/MSFT/Microsoft Corporation (MSFT) Q1 2023 Earnings Call Transcript.pdf +0 -0
  20. EarningsTranscripts (PDF)/MSFT/Microsoft Corporation (MSFT) Q1 2024 Earnings Call Transcript.pdf +0 -0
  21. EarningsTranscripts (PDF)/MSFT/Microsoft Corporation (MSFT) Q2 2023 Earnings Call Transcript.pdf +0 -0
  22. EarningsTranscripts (PDF)/MSFT/Microsoft Corporation (MSFT) Q3 2023 Earnings Call Transcript.pdf +0 -0
  23. EarningsTranscripts (PDF)/MSFT/Microsoft Corporation (MSFT) Q4 2023 Earnings Call Transcript.pdf +0 -0
  24. EarningsTranscripts (PDF)/MSFT/Microsoft Corporation's (MSFT) CEO Satya Nadella on Q2 2022 Results - Earnings Call Transcript.pdf +0 -0
  25. EarningsTranscripts (PDF)/MSFT/Microsoft's (MSFT) CEO Satya Nadella on Q3 2022 Results - Earnings Call Transcript.pdf +0 -0
  26. EarningsTranscripts (PDF)/NVDA/NVIDIA Corp. (NVDA) Q1 2024 Earnings Call Transcript.pdf +0 -0
  27. EarningsTranscripts (PDF)/NVDA/NVIDIA Corp. (NVDA) Q2 2024 Earnings Call Transcript.pdf +0 -0
  28. EarningsTranscripts (PDF)/NVDA/NVIDIA Corp. (NVDA) Q4 2023 Earnings Call Transcript.pdf +0 -0
  29. EarningsTranscripts (PDF)/NVDA/NVIDIA Corporation (NVDA) CEO Jensen Huang On Q1 2023 Results - Earnings Call Transcript.pdf +0 -0
  30. EarningsTranscripts (PDF)/NVDA/NVIDIA Corporation (NVDA) CEO Jensen Huang on Q2 2023 Results - Earnings Call Transcript.pdf +0 -0
  31. EarningsTranscripts (PDF)/NVDA/NVIDIA Corporation (NVDA) Q3 2023 Earnings Call Transcript.pdf +0 -0
  32. EarningsTranscripts (PDF)/NVDA/NVIDIA Corporation (NVDA) Q3 2024 Earnings Call Transcript.pdf +0 -0
  33. README.md +4 -4
  34. app.py +35 -0
  35. chainlit.md +11 -0
  36. earnings_app.py +170 -0
  37. requirements.txt +12 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+ RUN useradd -m -u 1000 user
3
+ USER user
4
+ ENV HOME=/home/user \
5
+ PATH=/home/user/.local/bin:$PATH
6
+ WORKDIR $HOME/app
7
+ COPY --chown=user . $HOME/app
8
+ COPY ./requirements.txt ~/app/requirements.txt
9
+ RUN pip install -r requirements.txt
10
+ COPY . .
11
+ CMD ["chainlit", "run", "app.py", "--port", "7860"]
EarningsTranscripts (PDF)/AAPL/Apple (AAPL) Q2 2023 Earnings Call Transcript.pdf ADDED
Binary file (138 kB). View file
 
EarningsTranscripts (PDF)/AAPL/Apple Inc. (AAPL) CEO Tim Cook on Q1 2022 Results - Earnings Call Transcript.pdf ADDED
Binary file (133 kB). View file
 
EarningsTranscripts (PDF)/AAPL/Apple Inc. (AAPL) CEO Tim Cook on Q2 2022 Results - Earnings Call Transcript.pdf ADDED
Binary file (140 kB). View file
 
EarningsTranscripts (PDF)/AAPL/Apple Inc. (AAPL) Q3 2023 Earnings Call Transcript.pdf ADDED
Binary file (137 kB). View file
 
EarningsTranscripts (PDF)/AAPL/Apple Inc. (AAPL) Q4 2022 Earnings Call Transcript.pdf ADDED
Binary file (144 kB). View file
 
EarningsTranscripts (PDF)/AAPL/Apple Inc. (AAPL) Q4 2023 Earnings Call Transcript.pdf ADDED
Binary file (145 kB). View file
 
EarningsTranscripts (PDF)/AAPL/Apple, Inc. (AAPL) CEO Tim Cook on Q3 2022 Results - Earnings Call Transcript.pdf ADDED
Binary file (135 kB). View file
 
EarningsTranscripts (PDF)/AAPL/Apple, Inc. (AAPL) Q1 2023 Earnings Call Transcript.pdf ADDED
Binary file (133 kB). View file
 
EarningsTranscripts (PDF)/GOOG/Alphabet Inc. (GOOG) CEO Sundar Pichai on Q2 2022 Results - Earnings Call Transcript.pdf ADDED
Binary file (135 kB). View file
 
EarningsTranscripts (PDF)/GOOG/Alphabet Inc. (GOOG) Q1 2023 Earnings Call Transcript.pdf ADDED
Binary file (144 kB). View file
 
EarningsTranscripts (PDF)/GOOG/Alphabet Inc. (GOOG) Q2 2023 Earnings Call Transcript.pdf ADDED
Binary file (142 kB). View file
 
EarningsTranscripts (PDF)/GOOG/Alphabet Inc. (GOOG) Q3 2022 Earnings Call Transcript.pdf ADDED
Binary file (140 kB). View file
 
EarningsTranscripts (PDF)/GOOG/Alphabet Inc. (GOOG) Q3 2023 Earnings Call Transcript.pdf ADDED
Binary file (133 kB). View file
 
EarningsTranscripts (PDF)/GOOG/Alphabet Inc. (GOOG) Q4 2022 Earnings Call Transcript.pdf ADDED
Binary file (137 kB). View file
 
EarningsTranscripts (PDF)/GOOG/Alphabet Inc.'s (GOOG) CEO Sundar Pichai on Q1 2022 Results - Earnings Call Transcript.pdf ADDED
Binary file (133 kB). View file
 
EarningsTranscripts (PDF)/MSFT/Microsoft Corporation (MSFT) CEO Satya Nadella on Q1 Fiscal 2022 Results - Earnings Call Transcript.pdf ADDED
Binary file (150 kB). View file
 
EarningsTranscripts (PDF)/MSFT/Microsoft Corporation (MSFT) CEO Satya Nadella on Q4 2022 Results - Earnings Call Transcript.pdf ADDED
Binary file (148 kB). View file
 
EarningsTranscripts (PDF)/MSFT/Microsoft Corporation (MSFT) Q1 2023 Earnings Call Transcript.pdf ADDED
Binary file (154 kB). View file
 
EarningsTranscripts (PDF)/MSFT/Microsoft Corporation (MSFT) Q1 2024 Earnings Call Transcript.pdf ADDED
Binary file (148 kB). View file
 
EarningsTranscripts (PDF)/MSFT/Microsoft Corporation (MSFT) Q2 2023 Earnings Call Transcript.pdf ADDED
Binary file (149 kB). View file
 
EarningsTranscripts (PDF)/MSFT/Microsoft Corporation (MSFT) Q3 2023 Earnings Call Transcript.pdf ADDED
Binary file (150 kB). View file
 
EarningsTranscripts (PDF)/MSFT/Microsoft Corporation (MSFT) Q4 2023 Earnings Call Transcript.pdf ADDED
Binary file (155 kB). View file
 
EarningsTranscripts (PDF)/MSFT/Microsoft Corporation's (MSFT) CEO Satya Nadella on Q2 2022 Results - Earnings Call Transcript.pdf ADDED
Binary file (151 kB). View file
 
EarningsTranscripts (PDF)/MSFT/Microsoft's (MSFT) CEO Satya Nadella on Q3 2022 Results - Earnings Call Transcript.pdf ADDED
Binary file (157 kB). View file
 
EarningsTranscripts (PDF)/NVDA/NVIDIA Corp. (NVDA) Q1 2024 Earnings Call Transcript.pdf ADDED
Binary file (149 kB). View file
 
EarningsTranscripts (PDF)/NVDA/NVIDIA Corp. (NVDA) Q2 2024 Earnings Call Transcript.pdf ADDED
Binary file (139 kB). View file
 
EarningsTranscripts (PDF)/NVDA/NVIDIA Corp. (NVDA) Q4 2023 Earnings Call Transcript.pdf ADDED
Binary file (132 kB). View file
 
EarningsTranscripts (PDF)/NVDA/NVIDIA Corporation (NVDA) CEO Jensen Huang On Q1 2023 Results - Earnings Call Transcript.pdf ADDED
Binary file (140 kB). View file
 
EarningsTranscripts (PDF)/NVDA/NVIDIA Corporation (NVDA) CEO Jensen Huang on Q2 2023 Results - Earnings Call Transcript.pdf ADDED
Binary file (137 kB). View file
 
EarningsTranscripts (PDF)/NVDA/NVIDIA Corporation (NVDA) Q3 2023 Earnings Call Transcript.pdf ADDED
Binary file (135 kB). View file
 
EarningsTranscripts (PDF)/NVDA/NVIDIA Corporation (NVDA) Q3 2024 Earnings Call Transcript.pdf ADDED
Binary file (148 kB). View file
 
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: Llmops Final Earnings
3
- emoji: 📚
4
- colorFrom: purple
5
- colorTo: green
6
  sdk: docker
7
  pinned: false
8
  license: apache-2.0
 
1
  ---
2
+ title: Barbie RAQA Application Chainlit Demo
3
+ emoji: 🔥
4
+ colorFrom: red
5
+ colorTo: red
6
  sdk: docker
7
  pinned: false
8
  license: apache-2.0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+
3
+ sys.path.append(".")
4
+
5
+ import chainlit as cl
6
+
7
+ from earnings_app import extract_information
8
+
9
+ @cl.author_rename
10
+ def rename(orig_author: str):
11
+ diamond_char = u'\U0001F537'
12
+ phrase = diamond_char + " Diamond Hands " + diamond_char
13
+ rename_dict = {"RetrievalQA": phrase}
14
+ return rename_dict.get(orig_author, orig_author)
15
+
16
+ @cl.on_chat_start
17
+ async def start():
18
+ """
19
+ This is called when the Chainlit chat is started!
20
+ """
21
+ chain = await extract_information()
22
+ cl.user_session.set("chain", chain)
23
+ await cl.Message("Welcome to the information extraction chat!").send()
24
+
25
+ @cl.on_message
26
+ async def main(message: cl.Message):
27
+ """
28
+ This is called when a message is received!
29
+ """
30
+ chain = cl.user_session.get("chain")
31
+ res = await chain.achat(message.content)
32
+ # res = await chain.aiinvoke({"input": message})
33
+ # res = res["text"]
34
+ out = str(res)
35
+ await cl.Message(content=out).send()
chainlit.md ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Assignment Part 2: Deploying Your Model to a Hugging Face Space
2
+
3
+ Now that you've done the hard work of setting up the RetrievalQA chain and sourcing your documents - let's tie it together in a ChainLit application.
4
+
5
+ ### Duplicating the Space
6
+
7
+ Since this is our first assignment, all you'll need to do is duplicate this space and add your own `OPENAI_API_KEY` as a secret in the space.
8
+
9
+ ### Conclusion
10
+
11
+ Now that you've shipped an LLM-powered application, it's time to share! 🚀
earnings_app.py ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Imports
3
+ import asyncio
4
+ import os
5
+ import openai
6
+
7
+ from typing import List, Optional
8
+ # from pydantic import BaseModel, Field
9
+
10
+ # from langchain.prompts import ChatPromptTemplate
11
+ # from langchain.pydantic_v1 import BaseModel
12
+ # from langchain.utils.openai_functions import convert_pydantic_to_openai_function
13
+ from llama_index.tools import FunctionTool
14
+ from llama_index.vector_stores.types import (
15
+ VectorStoreInfo,
16
+ MetadataInfo,
17
+ ExactMatchFilter,
18
+ MetadataFilters,
19
+ )
20
+ from llama_index.agent import OpenAIAgent
21
+ from llama_index.retrievers import VectorIndexRetriever
22
+ from llama_index.query_engine import RetrieverQueryEngine
23
+
24
+ from typing import List, Tuple, Any
25
+ from pydantic import BaseModel, Field
26
+ from llama_index import load_index_from_storage
27
+ from llama_index import set_global_handler
28
+ import llama_index
29
+ from llama_index.embeddings import OpenAIEmbedding
30
+ from llama_index import ServiceContext
31
+ from llama_index.llms import OpenAI
32
+ from llama_index import GPTVectorStoreIndex
33
+
34
+ set_global_handler("wandb", run_args={"project": "final-project-v1"})
35
+ wandb_callback = llama_index.global_handler
36
+
37
+ from dotenv import load_dotenv
38
+ load_dotenv()
39
+
40
+ openai.api_key = os.environ['OPENAI_API_KEY']
41
+
42
+ top_k = 3
43
+
44
+ vector_store_info = VectorStoreInfo(
45
+ content_info="transcripts of earnings calls",
46
+ metadata_info=[MetadataInfo(
47
+ name="title",
48
+ type="str",
49
+ description="Title of the earnings call",
50
+ ),
51
+ MetadataInfo(
52
+ name="period",
53
+ type="str",
54
+ description="Period of the earnings call"
55
+ ),
56
+ MetadataInfo(
57
+ name="ticker",
58
+ type="str",
59
+ description="Ticker of the company"
60
+ ),
61
+ MetadataInfo(
62
+ name="year",
63
+ type="str",
64
+ description="Year of the earnings call"
65
+ ),
66
+ MetadataInfo(
67
+ name="quarter",
68
+ type="str",
69
+ description="Quarter of the earnings call"
70
+ ),
71
+ MetadataInfo(
72
+ name="path",
73
+ type="str",
74
+ description="Path to the earnings call"
75
+ ),
76
+ ])
77
+
78
+ class AutoRetrieveModel(BaseModel):
79
+ query: str = Field(..., description="natural language query string")
80
+ filter_key_list: List[str] = Field(
81
+ ..., description="List of metadata filter field names"
82
+ )
83
+ filter_value_list: List[str] = Field(
84
+ ...,
85
+ description=(
86
+ "List of metadata filter field values (corresponding to names specified in filter_key_list)"
87
+ )
88
+ )
89
+
90
+ embed_model = OpenAIEmbedding()
91
+ chunk_size = 500
92
+
93
+ llm = OpenAI(
94
+ temperature=0,
95
+ model="gpt-4" ### YOUR CODE HERE
96
+ )
97
+
98
+ service_context = ServiceContext.from_defaults(
99
+ llm=llm,
100
+ chunk_size=chunk_size,
101
+ embed_model=embed_model,
102
+ )
103
+
104
+ index = GPTVectorStoreIndex.from_documents([], service_context=service_context)
105
+
106
+
107
+ # Main function to extract information
108
+ async def extract_information():
109
+ # Make sure to use a recent model that supports tools
110
+
111
+ storage_context = wandb_callback.load_storage_context(
112
+ artifact_url="llmop/final-project-v1/earnings-index:v1"
113
+ )
114
+
115
+ index = load_index_from_storage(storage_context, service_context=service_context)
116
+
117
+ def auto_retrieve_fn(
118
+ query: str, filter_key_list: List[str], filter_value_list: List[str]
119
+ ):
120
+ """Auto retrieval function.
121
+
122
+ Performs auto-retrieval from a vector database, and then applies a set of filters.
123
+
124
+ """
125
+ query = query or "Query"
126
+
127
+ exact_match_filters = [
128
+ ExactMatchFilter(key=k, value=v)
129
+ for k, v in zip(filter_key_list, filter_value_list)
130
+ ]
131
+ retriever = VectorIndexRetriever(
132
+ index, filters=MetadataFilters(filters=exact_match_filters), top_k=top_k
133
+ )
134
+ query_engine = RetrieverQueryEngine.from_args(retriever, service_context=service_context)
135
+
136
+ response = query_engine.query(query)
137
+ return str(response)
138
+
139
+ description = f"""
140
+ Who is the CEO of MSFT
141
+ The vector database schema is given below:
142
+ {vector_store_info.json()}
143
+ """
144
+ auto_retrieve_tool = FunctionTool.from_defaults(
145
+ fn=auto_retrieve_fn,
146
+ name="earnings-transcripts",
147
+ description=description,
148
+ fn_schema=AutoRetrieveModel
149
+ )
150
+
151
+ agent = OpenAIAgent.from_tools(
152
+ tools=[auto_retrieve_tool],
153
+ )
154
+
155
+ return agent
156
+
157
+
158
+ # if __name__ == "__main__":
159
+ # text = "Who is the CEO of MSFT."
160
+ # chain = extract_information()
161
+ # print(str(chain.chat(text)))
162
+
163
+ # async def extract_information_async(message: str):
164
+ # return str(chain.chat(text))
165
+
166
+ # async def main():
167
+ # res = await extract_information_async(text)
168
+ # print(res)
169
+
170
+ # asyncio.run(main())
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ chainlit
2
+ langchain
3
+ tiktoken
4
+ openai
5
+ faiss-cpu
6
+ llama-index==0.9.19
7
+ llama-hub
8
+ unstructured
9
+ lxml
10
+ cohere
11
+ wandb
12
+ pydantic