Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse files- app.py +69 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
+
print("Loading Ginie Solidity LLM...")
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("GinieAI/Solidity-LLM")
|
| 6 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 7 |
+
"GinieAI/Solidity-LLM",
|
| 8 |
+
torch_dtype=torch.float32, # CPU-safe for Space free tier
|
| 9 |
+
device_map="cpu"
|
| 10 |
+
)
|
| 11 |
+
print("Model ready!")
|
| 12 |
+
def generate_contract(instruction, max_tokens=600, temperature=0.7):
|
| 13 |
+
prompt = f"""### Instruction:
|
| 14 |
+
{instruction}
|
| 15 |
+
### Response:
|
| 16 |
+
"""
|
| 17 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 18 |
+
with torch.no_grad():
|
| 19 |
+
outputs = model.generate(
|
| 20 |
+
**inputs,
|
| 21 |
+
max_new_tokens=max_tokens,
|
| 22 |
+
temperature=temperature,
|
| 23 |
+
do_sample=True,
|
| 24 |
+
pad_token_id=tokenizer.eos_token_id
|
| 25 |
+
)
|
| 26 |
+
result = tokenizer.decode(outputs, skip_special_tokens=True)
|
| 27 |
+
# Return only the response part
|
| 28 |
+
if "### Response:" in result:
|
| 29 |
+
result = result.split("### Response:")[-1].strip()
|
| 30 |
+
return result
|
| 31 |
+
examples = [
|
| 32 |
+
["Write a Solidity ERC20 token contract with minting and burning."],
|
| 33 |
+
["Write a Solidity multisig wallet requiring 2 of 3 signatures."],
|
| 34 |
+
["Write a Solidity staking contract with 10% APY rewards."],
|
| 35 |
+
["Write a Solidity DAO governance contract with voting."],
|
| 36 |
+
["Write a Solidity NFT contract with whitelist minting."],
|
| 37 |
+
]
|
| 38 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="Ginie AI") as demo:
|
| 39 |
+
gr.Markdown("""
|
| 40 |
+
# 🧞 Ginie AI — Solidity Smart Contract Generator
|
| 41 |
+
**The AI built for Web3 developers** · [ginie.xyz](https://ginie.xyz)
|
| 42 |
+
|
| 43 |
+
Describe the smart contract you need in plain English. Ginie generates production-ready Solidity.
|
| 44 |
+
""")
|
| 45 |
+
|
| 46 |
+
with gr.Row():
|
| 47 |
+
with gr.Column(scale=1):
|
| 48 |
+
instruction = gr.Textbox(
|
| 49 |
+
label="What contract do you need?",
|
| 50 |
+
placeholder="e.g. Write a Solidity ERC20 token with minting, burning, and owner controls.",
|
| 51 |
+
lines=4
|
| 52 |
+
)
|
| 53 |
+
with gr.Row():
|
| 54 |
+
max_tokens = gr.Slider(100, 1000, value=600, label="Max tokens")
|
| 55 |
+
temperature = gr.Slider(0.1, 1.0, value=0.7, label="Creativity")
|
| 56 |
+
btn = gr.Button("🧞 Generate Contract", variant="primary")
|
| 57 |
+
|
| 58 |
+
with gr.Column(scale=2):
|
| 59 |
+
output = gr.Code(label="Generated Solidity", language="javascript")
|
| 60 |
+
|
| 61 |
+
gr.Examples(examples=examples, inputs=instruction)
|
| 62 |
+
btn.click(generate_contract, inputs=[instruction, max_tokens, temperature], outputs=output)
|
| 63 |
+
|
| 64 |
+
gr.Markdown("""
|
| 65 |
+
---
|
| 66 |
+
**⚠️ Always review AI-generated code before deploying to mainnet.**
|
| 67 |
+
Model: [GinieAI/Solidity-LLM](https://huggingface.co/GinieAI/Solidity-LLM) · License: MIT
|
| 68 |
+
""")
|
| 69 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers==4.40.0
|
| 2 |
+
torch==2.1.0
|
| 3 |
+
accelerate==0.29.0
|
| 4 |
+
gradio==4.44.0
|