Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,11 +2,12 @@
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import requests
|
| 4 |
import gradio as gr
|
|
|
|
| 5 |
|
| 6 |
-
# Load the Hugging Face model and tokenizer
|
| 7 |
-
model_name = "
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 10 |
|
| 11 |
# Groq API configuration
|
| 12 |
GROQ_API_KEY = "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"
|
|
@@ -31,8 +32,8 @@ def generate_smart_contract(language, requirements):
|
|
| 31 |
prompt = f"Generate a {language} smart contract with the following requirements: {requirements}"
|
| 32 |
|
| 33 |
# Use the Hugging Face model to generate code
|
| 34 |
-
inputs = tokenizer(prompt, return_tensors="pt")
|
| 35 |
-
outputs = model.generate(**inputs, max_length=
|
| 36 |
generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 37 |
|
| 38 |
# Enhance the code using Groq API
|
|
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import requests
|
| 4 |
import gradio as gr
|
| 5 |
+
import torch
|
| 6 |
|
| 7 |
+
# Load the Hugging Face model and tokenizer in 8-bit precision
|
| 8 |
+
model_name = "gpt2" # Smaller and faster model
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, load_in_8bit=True, device_map="auto")
|
| 11 |
|
| 12 |
# Groq API configuration
|
| 13 |
GROQ_API_KEY = "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"
|
|
|
|
| 32 |
prompt = f"Generate a {language} smart contract with the following requirements: {requirements}"
|
| 33 |
|
| 34 |
# Use the Hugging Face model to generate code
|
| 35 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda") # Move inputs to GPU
|
| 36 |
+
outputs = model.generate(**inputs, max_length=300) # Reduced max_length
|
| 37 |
generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 38 |
|
| 39 |
# Enhance the code using Groq API
|