Spaces:
Sleeping
Sleeping
tensorgirl
commited on
Update utils.py
Browse files
utils.py
CHANGED
@@ -13,15 +13,15 @@ from groq import Groq
|
|
13 |
import time
|
14 |
from openai import OpenAI
|
15 |
|
16 |
-
|
17 |
-
|
18 |
desc = pd.read_excel('Descriptor.xlsx',header = None)
|
19 |
desc_list = desc.iloc[:,0].to_list()
|
20 |
|
21 |
def callAzure(prompt,text):
|
22 |
|
23 |
-
url = "https://
|
24 |
-
api_key = "
|
25 |
client = OpenAI(base_url=url, api_key=api_key)
|
26 |
msg = "{} {}".format(prompt, text)
|
27 |
|
@@ -33,7 +33,7 @@ def callAzure(prompt,text):
|
|
33 |
}
|
34 |
],
|
35 |
model="azureai",
|
36 |
-
max_tokens =
|
37 |
)
|
38 |
|
39 |
return response.choices[0].message.content
|
@@ -78,7 +78,9 @@ def summary(input_json):
|
|
78 |
|
79 |
id = desc_list.index(input_json['Descriptor'])
|
80 |
long_text = filtering_results[1]
|
81 |
-
|
|
|
|
|
82 |
url = 'https://www.bseindia.com/xml-data/corpfiling/AttachLive/'+ input_json['FileURL'].split('Pname=')[-1]
|
83 |
|
84 |
output["Link to BSE website"] = url
|
@@ -90,14 +92,11 @@ def summary(input_json):
|
|
90 |
answer = "You are an financial expert" + callAzure(promptShort[id], long_text)
|
91 |
output['Short Summary'] = answer
|
92 |
|
93 |
-
|
94 |
-
output['Long summary'] = answer
|
95 |
-
|
96 |
-
prompt = "Answer in 1 word only. Financial SEO tag for this news article"
|
97 |
answer = callAzure(prompt, output['Short Summary'])
|
98 |
output['Tag'] = answer
|
99 |
|
100 |
-
prompt = "
|
101 |
answer = callAzure(prompt, output['Short Summary'])
|
102 |
output['Headline'] = answer
|
103 |
|
@@ -111,7 +110,15 @@ def summary(input_json):
|
|
111 |
prompt = "Answer in one word the sentiment of this News out of Positive, Negative or Neutral {}"
|
112 |
output['Sentiment'] = callAzure(prompt, output['Short Summary'])
|
113 |
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
# response = client.images.generate(
|
116 |
# model="dall-e-3",
|
117 |
# prompt=headline.text,
|
|
|
13 |
import time
|
14 |
from openai import OpenAI
|
15 |
|
16 |
+
openai_key = "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"
|
17 |
+
client = OpenAI(api_key = openai_key)
|
18 |
desc = pd.read_excel('Descriptor.xlsx',header = None)
|
19 |
desc_list = desc.iloc[:,0].to_list()
|
20 |
|
21 |
def callAzure(prompt,text):
|
22 |
|
23 |
+
url = "https://Meta-Llama-3-70B-Instruct-fkqip-serverless.eastus2.inference.ai.azure.com"
|
24 |
+
api_key = "o5yaLhTIvg0s5zuYVInBpyneEZO8oonY"
|
25 |
client = OpenAI(base_url=url, api_key=api_key)
|
26 |
msg = "{} {}".format(prompt, text)
|
27 |
|
|
|
33 |
}
|
34 |
],
|
35 |
model="azureai",
|
36 |
+
max_tokens = 1000
|
37 |
)
|
38 |
|
39 |
return response.choices[0].message.content
|
|
|
78 |
|
79 |
id = desc_list.index(input_json['Descriptor'])
|
80 |
long_text = filtering_results[1]
|
81 |
+
long_text = long_text.lstrip()
|
82 |
+
long_text = long_text.rstrip()
|
83 |
+
|
84 |
url = 'https://www.bseindia.com/xml-data/corpfiling/AttachLive/'+ input_json['FileURL'].split('Pname=')[-1]
|
85 |
|
86 |
output["Link to BSE website"] = url
|
|
|
92 |
answer = "You are an financial expert" + callAzure(promptShort[id], long_text)
|
93 |
output['Short Summary'] = answer
|
94 |
|
95 |
+
prompt = "Answer in 1 word only. Financial SEO tag for this news article. Nothing more than that"
|
|
|
|
|
|
|
96 |
answer = callAzure(prompt, output['Short Summary'])
|
97 |
output['Tag'] = answer
|
98 |
|
99 |
+
prompt = "Answer in single sentence. A headline for this News Article. Nothing more than that"
|
100 |
answer = callAzure(prompt, output['Short Summary'])
|
101 |
output['Headline'] = answer
|
102 |
|
|
|
110 |
prompt = "Answer in one word the sentiment of this News out of Positive, Negative or Neutral {}"
|
111 |
output['Sentiment'] = callAzure(prompt, output['Short Summary'])
|
112 |
|
113 |
+
completion = client.chat.completions.create(
|
114 |
+
model="gpt-4-turbo-preview",
|
115 |
+
messages=[
|
116 |
+
{"role": "system", "content": "You are a financial expert. Help the client with summarizing the financial newsletter"},
|
117 |
+
{"role": "user", "content": "{} {}".format(promptLong[id], long_text)}
|
118 |
+
]
|
119 |
+
)
|
120 |
+
|
121 |
+
output['Long summary'] = completion.choices[0].message
|
122 |
# response = client.images.generate(
|
123 |
# model="dall-e-3",
|
124 |
# prompt=headline.text,
|