DataAIDemo / pages /Auto_Report_Generation.py
themeetjani's picture
Update pages/Auto_Report_Generation.py
9362e58 verified
import streamlit as st
from streamlit import session_state
import json
from io import StringIO
import openai
import json
import os
os.environ['OPENAI_API_KEY'] = "sk-proj-ZbejHdD4ZgJ5FFJ6LjMNT3BlbkFJ1WHLrJMFL03D8cMWSoFY"
openai.api_key = os.environ['OPENAI_API_KEY']
st.set_page_config(
page_title="Auto_Report_Generation.py",
page_icon="๐Ÿ‘‹",
)
#need to define openai key or set it as environment variable first.
#openai function with prompting to generate l1 report.
#the below code is for fetching company report.
def all_combined(company_details):
response = openai.ChatCompletion.create(
model="gpt-4-turbo",
messages=[
{
"role": "system",
"content": f"following details are given for the company. details : {company_details}",
},
{
"role": "user",
"content": "Generate a detailed report out of this content. Please include all the details. Don't leave out any information. Give very detailed information about adverse media. And give very detailed report structure wise. Give contact details and employee details in a table. Please don't mention confirmed status or client in the table. Also give nice introduction first.<<REMEMBER>>\n mention that the information is provided by client. Don't mention the identifier tools. Mask it with some unknown source. Also mention number of confirmed sources by analyst" }
],
temperature=0.6,
max_tokens=1500,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response.choices[0].message.content
# if uploaded_file is not None:
# # To read file as bytes:
# bytes_data = uploaded_file.getvalue()
# st.write(bytes_data)
# # To convert to a string based IO:
# stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
# st.write(stringio)
# # To read file as string:
# string_data = stringio.read()
# st.write(string_data)
# # Can be used wherever a "file-like" object is accepted:
# dataframe = pd.read_csv(uploaded_file)
# st.write(dataframe)
st.write("# Auto Report Generation.! ๐Ÿ‘‹")
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
# To convert to a string based IO:
stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
string_data = stringio.read()
st.text_area("Report", value = all_combined(string_data[:100000]))