Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/doc#986 - Document best practice on main script #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions src/main_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,30 @@ def generate_image(state):
notify(state, "success", f"Image created!")




# Variables
tweet = ""
prompt = ""
n_requests = 0

topic = "AI"
mood = "inspirational"
style = "elonmusk"

image = None

# Called whever there is a problem
def on_exception(state, function_name: str, ex: Exception):
logging.error(f"Problem {ex} \nin {function_name}")
notify(state, 'error', f"Problem {ex} \nin {function_name}")


# Markdown for the entire page
## <text|
## |text>
## "text" here is just a name given to my part/my section
## it has no meaning in the code
page = """
if __name__ == "__main__":
# Variables
tweet = ""
prompt = ""
n_requests = 0

topic = "AI"
mood = "inspirational"
style = "elonmusk"

image = None

# Markdown for the entire page
## <text|
## |text>
## "text" here is just a name given to my part/my section
## it has no meaning in the code
page = """
<|container|
# **Tweet**{: .color-primary} Generation

Expand Down Expand Up @@ -198,8 +197,6 @@ def on_exception(state, function_name: str, ex: Exception):

Original code can be found [here](https://github.com/kinosal/tweet)
|>
"""
"""


if __name__ == "__main__":
Gui(page).run(title='Tweet Generation', debug=True, port=2436)
74 changes: 36 additions & 38 deletions src/main_tgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,57 +121,55 @@ def generate_image(state):
notify(state, "success", f"Image created!")




# Variables
tweet = ""
prompt = ""
n_requests = 0

topic = "AI"
mood = "inspirational"
style = "elonmusk"

image = None

# Called whever there is a problem
def on_exception(state, function_name: str, ex: Exception):
logging.error(f"Problem {ex} \nin {function_name}")
notify(state, 'error', f"Problem {ex} \nin {function_name}")


with tgb.Page() as page:
with tgb.part("container"):
tgb.text("# Tweet Generation", mode="md")
tgb.text("This mini-app generates Tweets using OpenAI's GPT-3 based [Davinci model](https://beta.openai.com/docs/models/overview) for texts and [DALL·E](https://beta.openai.com/docs/guides/images) for images.", mode="md")
if __name__ == "__main__":
# Variables
tweet = ""
prompt = ""
n_requests = 0

with tgb.layout(columns="1 1 1", gap="30px", class_name="card"):
with tgb.part():
tgb.text("## Topic (or hashtag)", mode="md")
tgb.input("{topic}", label="Topic (or hashtag)")
with tgb.part():
tgb.text("## Mood", mode="md")
tgb.input("{mood}", label="Mood (e.g. inspirational, funny, serious) (optional)")
with tgb.part():
tgb.text("## Twitter account", mode="md")
tgb.input("{style}", label="Twitter account handle to style-copy recent Tweets (optional)")
topic = "AI"
mood = "inspirational"
style = "elonmusk"

tgb.button("Generate", on_action=generate_text)
image = None

tgb.html("hr")

tgb.text("## Generated Tweets", mode="md")
tgb.input("{tweet}", multiline=True, label="Resulting tweet", class_name="fullwidth")
with tgb.Page() as page:
with tgb.part("container"):
tgb.text("# Tweet Generation", mode="md")
tgb.text("This mini-app generates Tweets using OpenAI's GPT-3 based [Davinci model](https://beta.openai.com/docs/models/overview) for texts and [DALL·E](https://beta.openai.com/docs/guides/images) for images.", mode="md")

tgb.button("Generate image", on_action=generate_image, active="{prompt != '' and tweet != ''}", class_name="text-center text_center center")
with tgb.layout(columns="1 1 1", gap="30px", class_name="card"):
with tgb.part():
tgb.text("## Topic (or hashtag)", mode="md")
tgb.input("{topic}", label="Topic (or hashtag)")
with tgb.part():
tgb.text("## Mood", mode="md")
tgb.input("{mood}", label="Mood (e.g. inspirational, funny, serious) (optional)")
with tgb.part():
tgb.text("## Twitter account", mode="md")
tgb.input("{style}", label="Twitter account handle to style-copy recent Tweets (optional)")

with tgb.part(render="{prompt != '' and tweet != '' and image is not None}", class_name="card text-center"):
tgb.text("## Image from Dall-e", mode="md")
tgb.image("{image}", height="400px")
tgb.button("Generate", on_action=generate_text)

tgb.text("Code from [@kinosal](https://twitter.com/kinosal)", mode="md")
tgb.text("Original code can be found [here](https://github.com/kinosal/tweet)", mode="md")
tgb.html("hr")

tgb.text("## Generated Tweets", mode="md")
tgb.input("{tweet}", multiline=True, label="Resulting tweet", class_name="fullwidth")

tgb.button("Generate image", on_action=generate_image, active="{prompt != '' and tweet != ''}", class_name="text-center text_center center")

with tgb.part(render="{prompt != '' and tweet != '' and image is not None}", class_name="card text-center"):
tgb.text("## Image from Dall-e", mode="md")
tgb.image("{image}", height="400px")

tgb.text("Code from [@kinosal](https://twitter.com/kinosal)", mode="md")
tgb.text("Original code can be found [here](https://github.com/kinosal/tweet)", mode="md")

if __name__ == "__main__":
Gui(page).run(title='Tweet Generation', port=3455)