DataAIDemo / pages /Auto_Report_Generation.py
themeetjani's picture
Update pages/Auto_Report_Generation.py
e7a366d verified
raw
history blame
2.35 kB
import streamlit as st
from streamlit import session_state
import json
from io import StringIO
import openai
import json
import os
openai.api_key = os.getenv("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-1106-preview",
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 'report' not in session_state:
session_state['report']= ""
def classify():
session_state['report'] = all_combined(uploaded_file)
st.text_area("result", value=session_state['report'])
st.button("Generate a Report", on_click=classify)