Comments (3)
Hey @deepakmehta79, you can absolutely do this pretty easily, but i didn't build it directly in due to the potential risk of calling exec
.
Here's an example
import pandas as pd
import sketch
import random
df = pd.DataFrame(
{
"transaction_id": [random.randint(1, 5121) for _ in range(20)],
"fruit": [random.choice(["Orange", "Apple", "Banana"]) for _ in range(20)],
"price": [random.randint(1, 323)/100 for _ in range(20)],
}
)
code_to_run = df.sketch.howto("find the average price and standard deviation for each fruit and print it out in a nice way", call_display=False)
exec(code_to_run)
Note 2 things,
(1) I use call_display
on the sketch.howto, this means that it will return a string i can store into a variable.
(2) I execute that code with exec
The reason i avoided including this as the default behavior was due to security implications of running code that you get generated from a model (who knows what it could do!) and also for transparency of process.
Rather than simply assuming the AI is right, the extra copy-paste step helps bring transparency into what is happening, so any data-results can be defended!
That said, I completely understand the desire to expidite the process when you're just hacking away, so i'd suggest something like that.
Also, if you want a "step up", here's a fun snippet i just threw together:
@pd.api.extensions.register_dataframe_accessor("run")
class SketchHelper:
def __init__(self, pandas_obj):
self._obj = pandas_obj
def __call__(self, command):
code_to_run = self._obj.sketch.howto(command, call_display=False)
exec(code_to_run)
followed by:
df.run("find the average price and standard deviation for each fruit and print it out in a nice way")
which works!~
Use this power at your own discretion!
from sketch.
Hi @bluecoconut, thank you so much, this is indeed super cool.
I am trying to following your suggesting, and trying to embed in the streamlit app but I am getting the following error:
RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'.
Traceback:
File "/opt/conda/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script
exec(code, module.dict)
import sketch
File "/opt/conda/lib/python3.10/site-packages/sketch/init.py", line 2, in
from .pandas_extension import SketchHelper # noqa
File "/opt/conda/lib/python3.10/site-packages/sketch/pandas_extension.py", line 16, in
import lambdaprompt
File "/opt/conda/lib/python3.10/site-packages/lambdaprompt/init.py", line 12, in
nest_asyncio.apply()
File "/opt/conda/lib/python3.10/site-packages/nest_asyncio.py", line 18, in apply
loop = loop or asyncio.get_event_loop()
File "/opt/conda/lib/python3.10/site-packages/nest_asyncio.py", line 45, in _get_event_loop
loop = events.get_event_loop_policy().get_event_loop()
File "/opt/conda/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
from sketch.
Hey @deepakmehta79 ,
This seems to be a conflict in nest_asyncio
and streamlit
the fix seems to be adding a few lines to the top of the file.
import asyncio
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
If you add this before import streamlit as st
then things should work.
from sketch.
Related Issues (20)
- Wrong result for query "Get the top 5 grossing states" in sample colab HOT 1
- <IPython.core.display.HTML object> error HOT 4
- Misspelling error HOT 1
- Can we calculate the Token costs (aka figure out what OpenAI will charge) HOT 1
- Joining dataframes HOT 3
- AttributeError: 'DataFrame' object has no attribute 'sketch' HOT 2
- Question : What is the use of to_b64() and from_b64() ? Why are they used? HOT 1
- and how to check that I'm using openai? HOT 3
- Local Mode fails on GGML models
- sketch.ask "Plot a bar chart..." in jupyter lab not including new lines.. HOT 3
- LAMBDAPROMPT_BACKEND = StarCoder causes a runtime error HOT 1
- Gunicron FastAPI - Value Error while importing sketch HOT 7
- I want to implement a google palm swtich HOT 1
- There is a validation error HOT 4
- sketch package no longer working in Google collab HOT 5
- LAMBDAPROMPT_BACKEND = StarCoder causes runtime ValidationError on .sketch.ask
- Privacy Policy HOT 2
- Not working HOT 2
- Discord link not working HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sketch.