Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ import uuid
|
|
| 6 |
import time
|
| 7 |
|
| 8 |
def extract_react_preview(code: str) -> str:
|
| 9 |
-
# Wrap code in a full HTML React preview template
|
| 10 |
return f"""
|
| 11 |
<!DOCTYPE html>
|
| 12 |
<html>
|
|
@@ -39,12 +38,21 @@ def run_app(user_input, enhance_prompt, action, state, progress=gr.Progress()):
|
|
| 39 |
model = genai.GenerativeModel("gemini-pro")
|
| 40 |
|
| 41 |
progress(0.2, desc="Sending prompt to Gemini...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
prompt_text = f"""Create a full React app based on this idea:
|
| 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("```")
|
|
|
|
| 6 |
import time
|
| 7 |
|
| 8 |
def extract_react_preview(code: str) -> str:
|
|
|
|
| 9 |
return f"""
|
| 10 |
<!DOCTYPE html>
|
| 11 |
<html>
|
|
|
|
| 38 |
model = genai.GenerativeModel("gemini-pro")
|
| 39 |
|
| 40 |
progress(0.2, desc="Sending prompt to Gemini...")
|
| 41 |
+
|
| 42 |
+
if "weather" in user_input.lower() or "temperature" in user_input.lower():
|
| 43 |
+
from datetime import datetime
|
| 44 |
+
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 45 |
+
fake_weather = f"🌤️ As of {now}, the weather is sunny and 30°C in Lahore."
|
| 46 |
+
return fake_weather, None, "<p>Weather bot reply successful.</p>", {}, {}
|
| 47 |
+
|
| 48 |
prompt_text = f"""Create a full React app based on this idea:
|
| 49 |
{user_input}
|
| 50 |
Return only relevant files like App.jsx, index.html, styles, utils or components in plain code blocks with filenames."""
|
| 51 |
|
| 52 |
try:
|
| 53 |
response = model.generate_content(prompt_text)
|
| 54 |
+
print("🔍 FULL GEMINI RESPONSE RAW >>>\n", response)
|
| 55 |
+
print("🔍 Gemini TEXT PREVIEW >>>\n", getattr(response, "text", "(no .text found)"))
|
| 56 |
if not hasattr(response, "text") or not response.text.strip():
|
| 57 |
raise ValueError("Gemini response is empty.")
|
| 58 |
parts = response.text.split("```")
|