Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -83,25 +83,32 @@ def generate_synthetic_data(description, columns):
|
|
83 |
# Load the Llama model only when generating data
|
84 |
load_llama_model()
|
85 |
|
|
|
86 |
formatted_prompt = format_prompt(description, columns)
|
87 |
-
payload = {"inputs": formatted_prompt, "parameters": generation_params}
|
88 |
-
headers = {"Authorization": f"Bearer {hf_token}"}
|
89 |
|
90 |
-
|
|
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
except Exception as e:
|
102 |
print(f"Error in generate_synthetic_data: {e}")
|
103 |
return f"Error: {e}"
|
104 |
|
|
|
105 |
def generate_large_synthetic_data(description, columns, num_rows=1000, rows_per_generation=100):
|
106 |
data_frames = []
|
107 |
num_iterations = num_rows // rows_per_generation
|
|
|
83 |
# Load the Llama model only when generating data
|
84 |
load_llama_model()
|
85 |
|
86 |
+
# Prepare the input for the Llama model
|
87 |
formatted_prompt = format_prompt(description, columns)
|
|
|
|
|
88 |
|
89 |
+
# Tokenize the prompt
|
90 |
+
inputs = tokenizer_llama(formatted_prompt, return_tensors="pt").to(model_llama.device)
|
91 |
|
92 |
+
# Generate synthetic data
|
93 |
+
with torch.no_grad():
|
94 |
+
outputs = model_llama.generate(
|
95 |
+
**inputs,
|
96 |
+
max_length=512,
|
97 |
+
top_p=generation_params["top_p"],
|
98 |
+
temperature=generation_params["temperature"],
|
99 |
+
num_return_sequences=1
|
100 |
+
)
|
101 |
+
|
102 |
+
# Decode the generated output
|
103 |
+
generated_text = tokenizer_llama.decode(outputs[0], skip_special_tokens=True)
|
104 |
+
|
105 |
+
# Return the generated synthetic data
|
106 |
+
return generated_text
|
107 |
except Exception as e:
|
108 |
print(f"Error in generate_synthetic_data: {e}")
|
109 |
return f"Error: {e}"
|
110 |
|
111 |
+
|
112 |
def generate_large_synthetic_data(description, columns, num_rows=1000, rows_per_generation=100):
|
113 |
data_frames = []
|
114 |
num_iterations = num_rows // rows_per_generation
|