-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticipant.py
93 lines (67 loc) · 2.85 KB
/
participant.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import streamlit as st
import os
import random
import requests
from artery import ArteryPrinter
from artery import pick_coupon
from artery import ExperienceReceipt, ReceiptImage, ReceiptText, CrazyText
FLASK_SERVICE_URL = "http://localhost:5000/generate"
with open( "streamlit_style.css" ) as css:
st.markdown( f'<style>{css.read()}</style>' , unsafe_allow_html= True)
# Display a fixed image at the top of the screen
top_image_path = "ccc/MEGAVIBE_teal.png"
st.image(top_image_path, use_column_width=True)
st.header("EXPERIENCE GENERATOR")
# set up a placeholder for a very simple layout
placeholder = st.empty()
# CCC logo at top left hand corner:
st.sidebar.image("ccc/ccc-cyber-teal.png")
# Password input
password_input = st.sidebar.text_input("ENTER THE PASSWORD", type="password", key="password",
help="The four most commonly used passwords are...",)
def random_gif():
return os.path.join("animated_gifs", random.choice(os.listdir("animated_gifs")))
def prep_text(text):
"""Replace curly apostrophes with straight ones."""
return text.replace('\u2018', "'").replace('\u2019', "'")
# Function to print the receipt
def print_receipt(receipt):
printer = ArteryPrinter()
for obj in receipt.receipt:
if isinstance(obj, ReceiptImage):
printer.print_image(obj.filepath)
elif isinstance(obj, ReceiptText):
printer.print_text(prep_text(obj.text), **obj.to_dict())
elif isinstance(obj, CrazyText):
printer.print_crazy_text(obj.text, **obj.to_dict())
printer.finish()
def full_receipt(text):
coupon1 = pick_coupon("coupons")
coupon2 = pick_coupon("coupons")
receipt = ExperienceReceipt(experience_text=text, coupon1=coupon1, coupon2=coupon2)
receipt.build_receipt()
return receipt
def generate_and_send_message():
# Make an HTTP GET request to the Flask service
response = requests.get(FLASK_SERVICE_URL)
generated_text = response.json()['experience'] # Extract the experience from the response
#send_to_discord(full_message)
return generated_text
# Check if the correct password is entered
if password_input in ("love", "secret", "sex", "God", "password"):
st.sidebar.text("ACCESS GRANTED.")
placeholder.image(random_gif(), width=300) # use_column_width=True) # Display a loading gif
generated_text = generate_and_send_message()
placeholder.write(generated_text)
#receipt = random.choice([full_receipt("ERRORS"), full_receipt(generated_text)])
receipt = full_receipt(generated_text)
# Display the PRINT button
if st.button("PRINT"):
try:
print_receipt(receipt)
st.write("Receipt printed successfully!")
except Exception as e:
st.write(f"Failed to print receipt: {e}")
#TODO
# play some music
# reset the page