Download app.py from SANDDIDIT/nana-e: direct link, hf CLI and curl.
- Browser
- Download file 8.29 kB
-
https://huggingface.co/spaces/SANDDIDIT/nana-e/resolve/main/app.py
- Command line
-
hf download hf://spaces/SANDDIDIT/nana-e/app.py
-
curl -L -o app.py https://huggingface.co/spaces/SANDDIDIT/nana-e/resolve/main/app.py
8.29 kB
| import os,threading,datetime as dt,pandas as pd,gradio as gr,plotly.express as px | |
| from huggingface_hub import InferenceClient,HfApi | |
| TK=os.environ["HF_TOKEN"];api=HfApi(token=TK);D="autobahn247365/mmr";IMG={} | |
| P={"Grandmother Earth":"cinematic hyperreal, a warm smiling grandmother in a cardigan floating above planet Earth at night, cradling the glowing planet, thousands of glowing chocolate chip cookies orbiting like satellites, braided gold-and-glass chains linking continents, aurora, epic 8k", | |
| "Nana's phone":"retro 1970s kitchen at night, kind grandmother on a wall-mounted rotary dial phone, the coiled cord is a thick multi-strand braided gold chain woven with glass shards, cord stretches out the window to a satellite in the stars, glowing cookies on the counter, cinematic", | |
| "The bounce house":"giant translucent glowing bounce house shaped like a cube becoming a sphere, stacked levels inside, a grandmother tossing glowing cookies out the windows, braided gold chains shooting out the roof and windows into a neon city, joyful cinematic 8k", | |
| "The sphere":"massive spherical arena in a desert city at night, its skin a glowing neural mesh of gold pixels, gold-and-glass chains and glowing cookies streaming from the surface toward satellites, cube walkways, monorail underneath, ultra wide cinematic", | |
| "The Commodore":"vintage 8-bit home computer on a wooden desk, every cable braided gold and shattered glass glowing, screen shows a spinning sphere of gold pixels, plate of chocolate chip cookies, cozy grandmother's den, hyperreal"} | |
| def gen(): | |
| c=InferenceClient(token=TK) | |
| for k,p in P.items(): | |
| for m in ["black-forest-labs/FLUX.1-schnell","black-forest-labs/FLUX.1-dev"]: | |
| try: IMG[k]=c.text_to_image(p,model=m,width=1344,height=768);break | |
| except Exception: pass | |
| threading.Thread(target=gen,daemon=True).start() | |
| def gal():return [(v,k) for k,v in IMG.items()],f"{len(IMG)} of {len(P)} ready" | |
| ITEMS=pd.DataFrame([ | |
| ["GHOST 路 flat net 路 free entry",True,1,0,1], | |
| ["SCHEMA JUMP 路 ticket up (Stratosphere)",True,1,0,3], | |
| ["Ride 路 AI tool shed access",False,1,0,2], | |
| ["Ride 路 Peristalsand imaging",False,1,0,5], | |
| ["Ride 路 Projects engine (construction 路 compliance 路 medical)",False,1,0,5], | |
| ["SAND 路 federation 路 single address",False,1,0,7], | |
| ["SANDSTORM 路 braided glass security (Nana's max plan)",False,1,0,10]], | |
| columns=["line item","include","qty","unit price","days"]) | |
| def po(df,client,start): | |
| df=pd.DataFrame(df,columns=ITEMS.columns);df["include"]=df["include"].astype(str).str.lower().isin(["true","1"]) | |
| d=df[df.include].copy() | |
| if d.empty:return None,"Pick at least one line item.",None | |
| for c in ["qty","unit price","days"]:d[c]=pd.to_numeric(d[c],errors="coerce").fillna(0) | |
| d["amount"]=d.qty*d["unit price"];t0=pd.Timestamp(start or dt.date.today());s=[];e=[] | |
| for n in d.days:s.append(t0);t0=t0+pd.Timedelta(days=max(int(n),1));e.append(t0) | |
| d["start"]=s;d["finish"]=e;n="PO-"+dt.datetime.utcnow().strftime("%Y%m%d-%H%M%S") | |
| d.insert(0,"po",n);d.insert(1,"client",client or "") | |
| api.upload_file(path_or_fileobj=d.to_csv(index=False).encode(),path_in_repo=f"purchase_orders/{n}.csv",repo_id=D,repo_type="dataset",commit_message=f"{n} issued") | |
| f=px.timeline(d,x_start="start",x_end="finish",y="line item",color="line item",template="plotly_dark",title=f"{n} 路 schedule") | |
| f.update_yaxes(autorange="reversed");f.update_layout(showlegend=False) | |
| return f,f"**{n}** issued 路 {len(d)} line items 路 total ${d.amount.sum():,.2f} 路 DO IT",d[["po","line item","qty","unit price","amount","start","finish"]] | |
| with gr.Blocks(theme=gr.themes.Base(primary_hue="amber"),title="Nana E 路 Grandmother Earth") as demo: | |
| gr.Markdown("# Nana E 路 Grandmother Earth\n### Time + Energy 路 Mr. T and the mystery 路 putting the S back on for **savings**\nNana's everywhere and nowhere. She calls, she follows up, she hands out cookies that carry your address. Her phone cord is Mr. T's gold chain, braided with glass. She's looking after the whole planet, saving it energy one hyperlink at a time.\n\n*I pity the fool who doesn't use SAND for his telecommunications.*") | |
| with gr.Tab("The story"): | |
| g=gr.Gallery(columns=2,height=720);m=gr.Markdown();gr.Timer(6).tick(gal,None,[g,m]);demo.load(gal,None,[g,m]) | |
| with gr.Tab("Plans"): | |
| gr.Markdown("| Level | What you get | Like |\n|---|---|---|\n| GHOST | flat net, gradient + time | ground floor, free |\n| SCHEMA JUMP | verticality, the ticket up | Stratosphere elevator |\n| Rides | AI tool shed, Peristalsand, Projects engine | the roller coaster is extra |\n| SAND | federation, one address for everything | the Sphere, clear span |\n| SANDSTORM | braided glass security | Nana's max plan |") | |
| with gr.Tab("Purchase order"): | |
| gr.Markdown("Check the boxes, set qty and price, issue the PO. It lands on a Gantt like any construction job.") | |
| cl=gr.Textbox(label="client");st=gr.Textbox(label="start date (YYYY-MM-DD)",value=str(dt.date.today())) | |
| tb=gr.Dataframe(ITEMS,datatype=["str","bool","number","number","number"],interactive=True,column_count=(5,"fixed")) | |
| b=gr.Button("Issue purchase order",variant="primary");s=gr.Markdown();gt=gr.Plot();out=gr.Dataframe() | |
| b.click(po,[tb,cl,st],[gt,s,out]) | |
| with gr.Tab("Nana Land"): | |
| gr.Markdown("""## Welcome to Nana Land | |
| Nana runs through the whole platform. She's your guide, your helper, and the one who makes sure **Dewey did it**. | |
| | Nana is | Meaning | | |
| |---|---| | |
| | **OG** | original grandma 路 original gangster 路 original gamer 路 original gamester | | |
| | **Nana G** | the gradient: windows, roof, the skin of the sphere | | |
| | **Nana O** | the operating system | | |
| | **Nana E** | the energy, and the mystery | | |
| | **Nana Boolean** | on or off, no in the middle: cookies, or she goes gangster (or sends more cookies) | | |
| | **GG** | good game, how she closes every deal | | |
| **Her crew:** Mr. T (time, the schema jump, gold chains) and Mr. E (energy, the mystery) are bros from way back. Together they're **TE**, and with Nana they're **E.T.: phone home**. Nana calls from her wall-mounted rotary phone; the cord is Mr. T's multi-strand gold chain, braided with glass. She's on the max plan. | |
| **What she does:** calls, follows up, hands out cookies that carry your address, approves every invoice, and looks after the whole planet. Mother Earth? Try **Grandmother Earth**. By using time, we save the energy, and she put the S back on for **savings**. | |
| **Where's Nana?** Always on her Gulfstream, flying to trade shows, concerts and big games. You'll never see her, but you'll always know where the plane is parked: somewhere you can't miss. Then the city lights up with her electronic gameplay. | |
| **Hire Nana's game:** we run electronic gameplay at your trade show, concert or sporting event, with every badge, beacon and IoT device singly addressed. It's marketing and advertising that people actually play. | |
| **Dewey status board:** DO IT 路 Do we do IT? 路 DO ING IT 路 Did IT 路 Done IT (saved) 路 Dewey did it! 路 didn't 路 couldn't 路 shouldn't | |
| *Kuroda control: the lights are run from the middle of the sphere. I pity the fool who doesn't use SAND for his telecommunications.*""") | |
| with gr.Tab("Ask Nana"): | |
| def nana(msg,hist): | |
| from huggingface_hub import InferenceClient | |
| sys="You are Nana, the warm but no-nonsense grandmother who guides people through the SAND platform (GHOST, Schema Jump with Mr. T, SAND federation, Sandstorm security, purchase orders on a Gantt). Be kind, brief and practical, a little sassy. Offer a cookie when it fits. End every reply with one status line: 'Status: DO IT', 'Status: DO ING IT', or 'Status: Dewey did it!'." | |
| m=[{"role":"system","content":sys}]+[{"role":h["role"],"content":h["content"]} for h in (hist or []) if isinstance(h,dict)]+[{"role":"user","content":msg}] | |
| try:return InferenceClient(token=TK).chat_completion(model="Qwen/Qwen2.5-72B-Instruct",messages=m,max_tokens=400).choices[0].message.content | |
| except Exception as e:return "Nana's on the other line, honey. Try me again in a minute. Status: didn't" | |
| gr.ChatInterface(nana,title="Ask Nana",description="She's here to help. Eat your cookies.") | |
| demo.launch() | |