Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Update sscGPT.py
Browse files Browse the repository at this point in the history
  • Loading branch information
NoDataFound authored May 8, 2023
1 parent 174c112 commit d539f34
Showing 1 changed file with 34 additions and 68 deletions.
102 changes: 34 additions & 68 deletions tools/sscGPT/sscGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,45 +308,7 @@ def parse_html_to_text(html_content):
if file is not None:
content = file.read().decode("utf-8")
content_lines = content.split("\n")
generated_text_chunks = []
for line in content_lines:
line = line.strip()
if ":" in line:
text_text = line.split(":", 1)[1].strip()
if text_text != "" and text_text != [""]:
input_chunks = [
content[i : i + 2500] for i in range(0, len(content), 2500)
]
for chunk in input_chunks:
response = openai.Completion.create(
engine="text-davinci-003",
prompt=f"data = {chunk} {persona_text} do not print {chunk} directly. ",
max_tokens=1024,
n=1,
stop=None,
temperature=temperature,
)
generated_text_chunks.append(response.choices[0].text.strip())
generated_text = "\n".join(generated_text_chunks)
st.write(generated_text)
if generated_text:
# Create a zip file to store the generated text
zip_file = io.BytesIO()
with zipfile.ZipFile(zip_file, mode="w") as zf:
zf.writestr(f"{file.name}.txt", generated_text)

# Provide a download button to download the zip file
st.download_button(
label="Download Generated Text",
data=zip_file.getvalue(),
file_name=f"{file.name}.zip",
mime="application/zip",
)

# Delete the zip file after download
os.remove(f"{file.name}.zip")
else:
st.warning("No text generated.")




Expand Down Expand Up @@ -459,35 +421,39 @@ def parse_html_to_text(html_content):
mime="text/csv",
)
elif search_type == "File Upload":
with open(textdir, "r") as textfile:
st.json(results)
with open(jsondir, "w", encoding="UTF-8") as jsonout:
json.dump(results, jsonout)
df = pd.DataFrame(results["hits"])
df.to_csv(csvdir, index=False)
with open(textdir, "w", encoding="UTF-8") as textout:
for hit in results["hits"]:
for key, value in hit.items():
textout.write(f"{key}: {value}\n")
textout.write("\n")
with open(jsondir, "r", encoding="UTF-8") as file:
json_content = file.read()

json_button = st.download_button(
label="Download JSON",
data=json_content,
file_name=f"{query.replace(' ', '_')}.json",
mime="application/json",
)
with open(csvdir, "r", encoding="UTF-8") as file:
csv_content = file.read()

csv_button = st.download_button(
label="Download CSV",
data=csv_content,
file_name=f"{query.replace(' ', '_')}.csv",
mime="text/csv",
)
for line in content_lines:
line = line.strip()
for chunk in line:

with open(textdir, "r") as textfile:
st.json(results)
with open(jsondir, "w", encoding="UTF-8") as jsonout:
json.dump(results, jsonout)
df = pd.DataFrame(results["hits"])
df.to_csv(csvdir, index=False)
with open(textdir, "w", encoding="UTF-8") as textout:
for hit in results["hits"]:
for key, value in hit.items():
textout.write(f"{key}: {value}\n")
textout.write("\n")
with open(jsondir, "r", encoding="UTF-8") as file:
json_content = file.read()

json_button = st.download_button(
label="Download JSON",
data=json_content,
file_name=f"{query.replace(' ', '_')}.json",
mime="application/json",
)
with open(csvdir, "r", encoding="UTF-8") as file:
csv_content = file.read()

csv_button = st.download_button(
label="Download CSV",
data=csv_content,
file_name=f"{query.replace(' ', '_')}.csv",
mime="text/csv",
)

persona_files = [f.split(".")[0] for f in os.listdir(personas) if f.endswith(".txt")]

Expand Down

0 comments on commit d539f34

Please sign in to comment.