diff --git "a/data.jsonl" "b/data.jsonl"
--- "a/data.jsonl"
+++ "b/data.jsonl"
@@ -7,4 +7,124 @@
{"text": "# Create an app to visualize sin, cos with slider and chart from taipy.gui import Gui from math import sin, cos, pi state = { \"frequency\": 1, \"decay\": 0.01, \"data\": [] } page = \"\"\" # Sine and Cosine Functions Frequency: <|{frequency}|slider|min=0|max=10|step=0.1|on_change=update|> Decay: <|{decay}|slider|min=0|max=1|step=0.01|on_change=update|> <|Data|chart|data={data}|> \"\"\" def update(state): x = [i/10 for i in range(100)] y1 = [sin(i*state.frequency*2*pi) * exp(-i*state.decay) for i in x] y2 = [cos(i*state.frequency*2*pi) * exp(-i*state.decay) for i in x] state.data = [ {\"name\": \"Sine\", \"data\": y1}, {\"name\": \"Cosine\", \"data\": y2} ] Gui(page).run(use_reloader=True, state=state)"}
{"text": "# Create app to visualize country population import numpy as np import pandas as pd from taipy.gui import Markdown from data.data import data selected_country = 'France' data_country_date = None representation_selector = ['Cumulative', 'Density'] selected_representation = representation_selector[0] layout = {'barmode':'stack', \"hovermode\":\"x\"} options = {\"unselected\":{\"marker\":{\"opacity\":0.5}}} def initialize_case_evolution(data, selected_country='France'): # Aggregation of the dataframe to erase the regions that will not be used here data_country_date = data.groupby([\"Country/Region\",'Date'])\\ .sum()\\ .reset_index() # a country is selected, here France by default data_country_date = data_country_date.loc[data_country_date['Country/Region']==selected_country] return data_country_date data_country_date = initialize_case_evolution(data) pie_chart = pd.DataFrame({\"labels\": [\"Deaths\", \"Recovered\", \"Confirmed\"],\"values\": [data_country_date.iloc[-1, 6], data_country_date.iloc[-1, 5], data_country_date.iloc[-1, 4]]}) def convert_density(state): if state.selected_representation == 'Density': df_temp = state.data_country_date.copy() df_temp['Deaths'] = df_temp['Deaths'].diff().fillna(0) df_temp['Recovered'] = df_temp['Recovered'].diff().fillna(0) df_temp['Confirmed'] = df_temp['Confirmed'].diff().fillna(0) state.data_country_date = df_temp else: state.data_country_date = initialize_case_evolution(data, state.selected_country) def on_change_country(state): # state contains all the Gui variables and this is through this state variable that we can update the Gui # state.selected_country, state.data_country_date, ... # update data_country_date with the right country (use initialize_case_evolution) print(\"Chosen country: \", state.selected_country) state.data_country_date = initialize_case_evolution(data, state.selected_country) state.pie_chart = pd.DataFrame({\"labels\": [\"Deaths\", \"Recovered\", \"Confirmed\"], \"values\": [state.data_country_date.iloc[-1, 6], state.data_country_date.iloc[-1, 5], state.data_country_date.iloc[-1, 4]]}) convert_density(state) page =\"\"\" # **Country**{: .color-primary} Statistics <|layout|columns=1 1 1| <|{selected_country}|selector|lov={selector_country}|on_change=on_change_country|dropdown|label=Country|> <|{selected_representation}|toggle|lov={representation_selector}|on_change=convert_density|> |>
<|layout|columns=1 1 1 1|gap=50px| <|card| **Deaths**{: .color-primary} <|{'{:,}'.format(int(data_country_date.iloc[-1]['Deaths'])).replace(',', ' ')}|text|class_name=h2|> |> <|card| **Recovered**{: .color-primary} <|{'{:,}'.format(int(data_country_date.iloc[-1]['Recovered'])).replace(',', ' ')}|text|class_name=h2|> |> <|card| **Confirmed**{: .color-primary} <|{'{:,}'.format(int(data_country_date.iloc[-1]['Confirmed'])).replace(',', ' ')}|text|class_name=h2|> |> |>
<|layout|columns=2 1| <|{data_country_date}|chart|type=bar|x=Date|y[3]=Deaths|y[2]=Recovered|y[1]=Confirmed|layout={layout}|options={options}|title=Covid Evolution|> <|{pie_chart}|chart|type=pie|values=values|labels=labels|title=Distribution between cases|> |> \"\"\" Gui(page).run(use_reloader=True, state=state)"}
{"text": "# Create Taipy app to generate mandelbrot fractals from taipy import Gui import numpy as np from PIL import Image import matplotlib.pyplot as plt WINDOW_SIZE = 500 cm = plt.cm.get_cmap(\"viridis\") def generate_mandelbrot( center: int = WINDOW_SIZE / 2, dx_range: int = 1000, dx_start: float = -0.12, dy_range: float = 1000, dy_start: float = -0.82, iterations: int = 50, max_value: int = 200, i: int = 0, ) -> str: mat = np.zeros((WINDOW_SIZE, WINDOW_SIZE)) for y in range(WINDOW_SIZE): for x in range(WINDOW_SIZE): dx = (x - center) / dx_range + dx_start dy = (y - center) / dy_range + dy_start a = dx b = dy for t in range(iterations): d = (a * a) - (b * b) + dx b = 2 * (a * b) + dy a = d h = d > max_value if h is True: mat[x, y] = t colored_mat = cm(mat / mat.max()) im = Image.fromarray((colored_mat * 255).astype(np.uint8)) path = f\"mandelbrot_{i}.png\" im.save(path) return path def generate(state): state.i = state.i + 1 state.path = generate_mandelbrot( dx_start=-state.dx_start / 100, dy_start=(state.dy_start - 100) / 100, iterations=state.iterations, i=state.i, ) i = 0 dx_start = 11 dy_start = 17 iterations = 50 path = generate_mandelbrot( dx_start=-dx_start / 100, dy_start=(dy_start - 100) / 100, ) page = \"\"\" # Mandelbrot Generator <|layout|columns=35 65| Display image from path <|{path}|image|width=500px|height=500px|class_name=img|> Iterations:
Create a slider to select iterations <|{iterations}|slider|min=10|max=50|continuous=False|on_change=generate|>
X Position:
<|{dy_start}|slider|min=0|max=100|continuous=False|on_change=generate|>
Y Position:
Slider dx_start <|{dx_start}|slider|min=0|max=100|continuous=False|on_change=generate|>
|> \"\"\" Gui(page).run(title=\"Mandelbrot Generator\") "}
-{"text": "# Create app to auto generate Tweeter status import logging import random import re # Import from 3rd party libraries from taipy.gui import Gui, notify, state import taipy # Import modules import oai # Configure logger logging.basicConfig(format=\"\\n%(asctime)s\\n%(message)s\", level=logging.INFO, force=True) def error_prompt_flagged(state, prompt): \"\"\"Notify user that a prompt has been flagged.\"\"\" notify(state, \"error\", \"Prompt flagged as inappropriate.\") logging.info(f\"Prompt flagged as inappropriate: {prompt}\") def error_too_many_requests(state): \"\"\"Notify user that too many requests have been made.\"\"\" notify( state, \"error\", \"Too many requests. Please wait a few seconds before generating another text or image.\", ) logging.info(f\"Session request limit reached: {state.n_requests}\") state.n_requests = 1 # Define functions def generate_text(state): \"\"\"Generate Tweet text.\"\"\" state.tweet = \"\" state.image = None # Check the number of requests done by the user if state.n_requests >= 5: error_too_many_requests(state) return # Check if the user has put a topic if state.topic == \"\": notify(state, \"error\", \"Please enter a topic\") return # Create the prompt and add a style or not if state.style == \"\": state.prompt = ( f\"Write a {state.mood}Tweet about {state.topic} in less than 120 characters \" f\"and with the style of {state.style}:\\n\\n\\n\\n\" ) else: state.prompt = f\"Write a {state.mood}Tweet about {state.topic} in less than 120 characters:\\n\\n\" # openai configured and check if text is flagged openai = oai.Openai() flagged = openai.moderate(state.prompt) if flagged: error_prompt_flagged(state, f\"Prompt: {state.prompt}\\n\") return else: # Generate the tweet state.n_requests += 1 state.tweet = openai.complete(state.prompt).strip().replace('\"', \"\") # Notify the user in console and in the GUI logging.info( f\"Topic: {state.prompt}{state.mood}{state.style}\\n\" f\"Tweet: {state.tweet}\" ) notify(state, \"success\", \"Tweet created!\") def generate_image(state): \"\"\"Generate Tweet image.\"\"\" notify(state, \"info\", \"Generating image...\") # Check the number of requests done by the user if state.n_requests >= 5: error_too_many_requests(state) return state.image = None # Creates the prompt prompt_wo_hashtags = re.sub(\"#[A-Za-z0-9_]+\", \"\", state.prompt) processing_prompt = ( \"Create a detailed but brief description of an image that captures \" f\"the essence of the following text:\\n{prompt_wo_hashtags}\\n\\n\" ) # Openai configured and check if text is flagged openai = oai.Openai() flagged = openai.moderate(processing_prompt) if flagged: error_prompt_flagged(state, processing_prompt) return else: state.n_requests += 1 # Generate the prompt that will create the image processed_prompt = ( openai.complete(prompt=processing_prompt, temperature=0.5, max_tokens=40) .strip() .replace('\"', \"\") .split(\".\")[0] + \".\" ) # Generate the image state.image = openai.image(processed_prompt) # Notify the user in console and in the GUI logging.info(f\"Tweet: {state.prompt}\\nImage prompt: {processed_prompt}\") notify(state, \"success\", f\"Image created!\") def feeling_lucky(state): \"\"\"Generate a feeling-lucky tweet.\"\"\" with open(\"moods.txt\") as f: sample_moods = f.read().splitlines() state.topic = \"an interesting topic\" state.mood = random.choice(sample_moods) state.style = \"\" generate_text(state) # 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}\") def update_documents(state: taipy.gui.state, docs: list[dict]) -> None: \"\"\" Updates a partial with a list of documents Args: state: The state of the GUI docs: A list of documents \"\"\" updated_part = \"\" for doc in docs: title = doc[\"title\"] summary = doc[\"summary\"] link = doc[\"link\"] updated_part += f\"\"\" {title}
{summary}
{qfqffqs}