Spaces:
Running
Running
robertselvam
commited on
Commit
•
7ebdef9
1
Parent(s):
4e91439
Update app.py
Browse files
app.py
CHANGED
@@ -30,6 +30,8 @@ import yfinance as yf
|
|
30 |
import pandas as pd
|
31 |
import nltk
|
32 |
from nltk.tokenize import sent_tokenize
|
|
|
|
|
33 |
|
34 |
class KeyValueExtractor:
|
35 |
|
@@ -42,6 +44,7 @@ class KeyValueExtractor:
|
|
42 |
pdf_file_path (str): The path to the input PDF file.
|
43 |
"""
|
44 |
self.model = "facebook/bart-large-mnli"
|
|
|
45 |
|
46 |
|
47 |
def get_url(self,keyword):
|
@@ -113,19 +116,34 @@ class KeyValueExtractor:
|
|
113 |
return result["output_text"]
|
114 |
|
115 |
def one_day_summary(self,content) -> None:
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
def extract_key_value_pair(self,content) -> None:
|
131 |
|
@@ -136,18 +154,31 @@ class KeyValueExtractor:
|
|
136 |
"""
|
137 |
|
138 |
try:
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
except Exception as e:
|
152 |
# If an error occurs during the key-value extraction process, log the error
|
153 |
logging.error(f"Error while extracting key-value pairs: {e}")
|
|
|
30 |
import pandas as pd
|
31 |
import nltk
|
32 |
from nltk.tokenize import sent_tokenize
|
33 |
+
from openai import OpenAI
|
34 |
+
|
35 |
|
36 |
class KeyValueExtractor:
|
37 |
|
|
|
44 |
pdf_file_path (str): The path to the input PDF file.
|
45 |
"""
|
46 |
self.model = "facebook/bart-large-mnli"
|
47 |
+
self.client = OpenAI()
|
48 |
|
49 |
|
50 |
def get_url(self,keyword):
|
|
|
116 |
return result["output_text"]
|
117 |
|
118 |
def one_day_summary(self,content) -> None:
|
119 |
+
conversation = [
|
120 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
121 |
+
{"role": "user", "content": f"i want detailed Summary from given finance details. i want information like what happen today comparing last day good or bad Bullish or Bearish like these details i want summary. content in backticks.```{content}```."}
|
122 |
+
]
|
123 |
+
|
124 |
+
# Call OpenAI GPT-3.5-turbo
|
125 |
+
chat_completion = self.client.chat.completions.create(
|
126 |
+
model = "gpt-3.5-turbo",
|
127 |
+
messages = conversation,
|
128 |
+
max_tokens=1000,
|
129 |
+
temperature=0
|
130 |
+
)
|
131 |
+
|
132 |
+
response = chat_completion.choices[0].message.content
|
133 |
+
return response
|
134 |
+
|
135 |
+
# # Use OpenAI's Completion API to analyze the text and extract key-value pairs
|
136 |
+
# response = openai.Completion.create(
|
137 |
+
# engine="text-davinci-003", # You can choose a different engine as well
|
138 |
+
# temperature = 0,
|
139 |
+
# prompt=f"i want detailed Summary from given finance details. i want information like what happen today comparing last day good or bad Bullish or Bearish like these details i want summary. content in backticks.```{content}```.",
|
140 |
+
# max_tokens=1000 # You can adjust the length of the response
|
141 |
+
# )
|
142 |
+
|
143 |
+
# # Extract and return the chatbot's reply
|
144 |
+
# result = response['choices'][0]['text'].strip()
|
145 |
+
# print(result)
|
146 |
+
# return result
|
147 |
|
148 |
def extract_key_value_pair(self,content) -> None:
|
149 |
|
|
|
154 |
"""
|
155 |
|
156 |
try:
|
157 |
+
conversation = [
|
158 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
159 |
+
{"role": "user", "content": f"Get maximum count meaningfull key value pairs. content in backticks.```{content}```."}
|
160 |
+
]
|
161 |
+
|
162 |
+
# Call OpenAI GPT-3.5-turbo
|
163 |
+
chat_completion = self.client.chat.completions.create(
|
164 |
+
model = "gpt-3.5-turbo",
|
165 |
+
messages = conversation,
|
166 |
+
max_tokens=1000,
|
167 |
+
temperature=0
|
168 |
+
)
|
169 |
+
response = chat_completion.choices[0].message.content
|
170 |
+
return response
|
171 |
+
# # Use OpenAI's Completion API to analyze the text and extract key-value pairs
|
172 |
+
# response = openai.Completion.create(
|
173 |
+
# engine="text-davinci-003", # You can choose a different engine as well
|
174 |
+
# temperature = 0,
|
175 |
+
# prompt=f"Get maximum count meaningfull key value pairs. content in backticks.```{content}```.",
|
176 |
+
# max_tokens=1000 # You can adjust the length of the response
|
177 |
+
# )
|
178 |
+
|
179 |
+
# # Extract and return the chatbot's reply
|
180 |
+
# result = response['choices'][0]['text'].strip()
|
181 |
+
# return result
|
182 |
except Exception as e:
|
183 |
# If an error occurs during the key-value extraction process, log the error
|
184 |
logging.error(f"Error while extracting key-value pairs: {e}")
|