File size: 5,070 Bytes
b2b50b7
 
 
 
0fe9a0c
 
 
b2b50b7
 
 
 
 
0fe9a0c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2b50b7
 
0fe9a0c
 
 
 
 
 
 
 
 
 
 
 
 
 
b2b50b7
 
 
0fe9a0c
 
 
 
 
 
 
 
 
 
 
 
 
b2b50b7
2c52598
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67a4038
2c52598
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2b50b7
 
 
 
67a4038
 
 
b2b50b7
 
2c52598
67a4038
2c52598
 
 
b2b50b7
2c52598
 
b2b50b7
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# app.py
import requests
import gradio as gr

# Hugging Face Inference API configuration
HF_API_KEY = "your_huggingface_api_key"  # Replace with your Hugging Face API key
HF_API_URL = f"https://api-inference.huggingface.co/models/codeparrot/codeparrot-small"

# Groq API configuration
GROQ_API_KEY = "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"
GROQ_API_URL = "https://api.groq.com/v1/completions"

# Function to query Hugging Face Inference API
def query_huggingface(prompt):
    try:
        headers = {
            "Authorization": f"Bearer {HF_API_KEY}",
            "Content-Type": "application/json"
        }
        data = {
            "inputs": prompt,
            "parameters": {
                "max_length": 150  # Limit the length of the generated text
            }
        }
        response = requests.post(HF_API_URL, headers=headers, json=data, timeout=30)  # Add timeout
        response.raise_for_status()  # Raise an error for bad responses (4xx, 5xx)
        return response.json()[0]["generated_text"]
    except Exception as e:
        return f"Error querying Hugging Face API: {str(e)}"

# Function to query Groq API
def query_groq(prompt):
    try:
        headers = {
            "Authorization": f"Bearer {GROQ_API_KEY}",
            "Content-Type": "application/json"
        }
        data = {
            "prompt": prompt,
            "max_tokens": 150
        }
        response = requests.post(GROQ_API_URL, headers=headers, json=data, timeout=10)  # Add timeout
        response.raise_for_status()  # Raise an error for bad responses (4xx, 5xx)
        return response.json()["choices"][0]["text"]
    except Exception as e:
        return f"Error querying Groq API: {str(e)}"

# Function to generate smart contract code
def generate_smart_contract(language, requirements):
    try:
        # Create a prompt for the model
        prompt = f"Generate a {language} smart contract with the following requirements: {requirements}"
        
        # Use Hugging Face Inference API to generate code
        generated_code = query_huggingface(prompt)
        
        # Enhance the code using Groq API
        enhanced_code = query_groq(generated_code)
        
        return enhanced_code
    except Exception as e:
        return f"Error generating smart contract: {str(e)}"

# Custom CSS for a 3D CGI Figma-like feel
custom_css = """
body {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: #fff;
    perspective: 1000px;
    overflow: hidden;
}

.gradio-container {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    transform-style: preserve-3d;
    transform: rotateY(0deg) rotateX(0deg);
    transition: transform 0.5s ease;
}

.gradio-container:hover {
    transform: rotateY(10deg) rotateX(10deg);
}

.gradio-input, .gradio-output {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 10px;
    padding: 10px;
    color: #fff;
    transform-style: preserve-3d;
    transition: transform 0.3s ease;
}

.gradio-input:focus, .gradio-output:focus {
    background: rgba(255, 255, 255, 0.3);
    outline: none;
    transform: translateZ(20px);
}

.gradio-button {
    background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
    border: none;
    border-radius: 10px;
    color: #fff;
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.3s ease;
    transform-style: preserve-3d;
}

.gradio-button:hover {
    background: linear-gradient(135deg, #2575fc 0%, #6a11cb 100%);
    transform: translateZ(10px);
}

h1 {
    text-align: center;
    font-size: 2.5em;
    margin-bottom: 20px;
    color: white; /* White title color */
    transform-style: preserve-3d;
    transform: translateZ(30px);
}

@keyframes float {
    0% {
        transform: translateY(0) translateZ(0);
    }
    50% {
        transform: translateY(-10px) translateZ(10px);
    }
    100% {
        transform: translateY(0) translateZ(0);
    }
}

.gradio-container {
    animation: float 4s ease-in-out infinite;
}
"""

# Gradio interface for the app
def generate_contract(language, requirements):
    return generate_smart_contract(language, requirements)

# Dropdown options for programming languages
languages = ["Solidity", "Vyper", "Rust", "JavaScript", "Python"]

interface = gr.Interface(
    fn=generate_contract,
    inputs=[
        gr.Dropdown(label="Programming Language", choices=languages, value="Solidity"),  # Dropdown menu
        gr.Textbox(label="Requirements", placeholder="e.g., ERC20 token with minting functionality")
    ],
    outputs=gr.Textbox(label="Generated Smart Contract"),
    title="Smart Contract Generator",
    description="Generate smart contracts using AI.",
    css=custom_css
)

# Launch the Gradio app
if __name__ == "__main__":
    interface.launch()