Spaces:
Runtime error
Runtime error
Update frontend_agent/ui_generator.py
Browse files
frontend_agent/ui_generator.py
CHANGED
|
@@ -8,17 +8,18 @@ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
|
|
| 8 |
|
| 9 |
def generate_react_component_llm(task_name):
|
| 10 |
"""
|
| 11 |
-
|
| 12 |
"""
|
| 13 |
prompt = f"""
|
| 14 |
-
Generate a React functional component for this frontend task
|
| 15 |
Task: {task_name}
|
| 16 |
-
Include
|
| 17 |
"""
|
| 18 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 19 |
outputs = model.generate(**inputs, max_new_tokens=250)
|
| 20 |
code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
return code
|
|
|
|
| 8 |
|
| 9 |
def generate_react_component_llm(task_name):
|
| 10 |
"""
|
| 11 |
+
Uses LLM to generate a React functional component for a frontend task.
|
| 12 |
"""
|
| 13 |
prompt = f"""
|
| 14 |
+
Generate a React functional component for this frontend task.
|
| 15 |
Task: {task_name}
|
| 16 |
+
Include props if needed and simple placeholder JSX.
|
| 17 |
"""
|
| 18 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 19 |
outputs = model.generate(**inputs, max_new_tokens=250)
|
| 20 |
code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 21 |
|
| 22 |
+
# Remove prompt part if included
|
| 23 |
+
if "Task:" in code:
|
| 24 |
+
code = code.split("Task:")[-1].strip()
|
| 25 |
return code
|