Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,9 +12,9 @@ def extract_react_preview(code: str) -> str:
|
|
| 12 |
<html>
|
| 13 |
<head>
|
| 14 |
<meta charset='UTF-8' />
|
| 15 |
-
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
|
| 16 |
-
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
|
| 17 |
-
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
|
| 18 |
<style>
|
| 19 |
body {{ font-family: sans-serif; padding: 20px; }}
|
| 20 |
</style>
|
|
@@ -43,8 +43,20 @@ def run_app(user_input, enhance_prompt, action, state, progress=gr.Progress()):
|
|
| 43 |
{user_input}
|
| 44 |
Return only relevant files like App.jsx, index.html, styles, utils or components in plain code blocks with filenames."""
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
files = {}
|
| 50 |
current_file = None
|
|
|
|
| 12 |
<html>
|
| 13 |
<head>
|
| 14 |
<meta charset='UTF-8' />
|
| 15 |
+
<script crossorigin src=\"https://unpkg.com/react@18/umd/react.development.js\"></script>
|
| 16 |
+
<script crossorigin src=\"https://unpkg.com/react-dom@18/umd/react-dom.development.js\"></script>
|
| 17 |
+
<script src=\"https://unpkg.com/@babel/standalone/babel.min.js\"></script>
|
| 18 |
<style>
|
| 19 |
body {{ font-family: sans-serif; padding: 20px; }}
|
| 20 |
</style>
|
|
|
|
| 43 |
{user_input}
|
| 44 |
Return only relevant files like App.jsx, index.html, styles, utils or components in plain code blocks with filenames."""
|
| 45 |
|
| 46 |
+
try:
|
| 47 |
+
response = model.generate_content(prompt_text)
|
| 48 |
+
if not hasattr(response, "text") or not response.text.strip():
|
| 49 |
+
raise ValueError("Gemini response is empty.")
|
| 50 |
+
parts = response.text.split("```")
|
| 51 |
+
except Exception as e:
|
| 52 |
+
print("❌ Gemini error:", e)
|
| 53 |
+
return (
|
| 54 |
+
"❌ Error: Could not generate app from Gemini.",
|
| 55 |
+
None,
|
| 56 |
+
"<p style='color:red;'>Gemini API failed or returned empty. Try again.</p>",
|
| 57 |
+
{},
|
| 58 |
+
{}
|
| 59 |
+
)
|
| 60 |
|
| 61 |
files = {}
|
| 62 |
current_file = None
|