Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,9 @@ from selenium.webdriver.common.by import By
|
|
| 25 |
from selenium.webdriver.support.ui import WebDriverWait
|
| 26 |
from selenium.webdriver.support import expected_conditions as EC
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
from huggingface_hub import hf_hub_download
|
| 30 |
|
| 31 |
# ---------------------------------------------------------------
|
|
@@ -163,15 +165,34 @@ def load_system_instruction(style="standard") -> str:
|
|
| 163 |
return open(f, encoding="utf-8").read()
|
| 164 |
|
| 165 |
def generate_html_from_text(text: str, temperature=0.5, style="standard") -> str:
|
|
|
|
| 166 |
api_key = os.environ["GEMINI_API_KEY"]
|
| 167 |
-
genai.
|
| 168 |
-
|
|
|
|
| 169 |
prompt = f"{load_system_instruction(style)}\n\n{text}"
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
s, e = raw.find("```html"), raw.rfind("```")
|
| 174 |
html = raw[s+7:e].strip() if s != -1 and e != -1 else raw
|
|
|
|
| 175 |
return enhance_font_awesome_layout(html)
|
| 176 |
|
| 177 |
def trim_image_whitespace(img: Image.Image, threshold=248, padding=20) -> Image.Image:
|
|
|
|
| 25 |
from selenium.webdriver.support.ui import WebDriverWait
|
| 26 |
from selenium.webdriver.support import expected_conditions as EC
|
| 27 |
|
| 28 |
+
# Updated: Use the new Google Genai library
|
| 29 |
+
from google import genai
|
| 30 |
+
from google.genai import types
|
| 31 |
from huggingface_hub import hf_hub_download
|
| 32 |
|
| 33 |
# ---------------------------------------------------------------
|
|
|
|
| 165 |
return open(f, encoding="utf-8").read()
|
| 166 |
|
| 167 |
def generate_html_from_text(text: str, temperature=0.5, style="standard") -> str:
|
| 168 |
+
# Updated: Use the new Google Genai client API
|
| 169 |
api_key = os.environ["GEMINI_API_KEY"]
|
| 170 |
+
client = genai.Client(api_key=api_key)
|
| 171 |
+
|
| 172 |
+
model_name = os.getenv("GEMINI_MODEL", "gemini-1.5-pro")
|
| 173 |
prompt = f"{load_system_instruction(style)}\n\n{text}"
|
| 174 |
+
|
| 175 |
+
# Configure generation parameters
|
| 176 |
+
config = types.GenerateContentConfig(
|
| 177 |
+
temperature=temperature,
|
| 178 |
+
top_p=0.7,
|
| 179 |
+
top_k=20,
|
| 180 |
+
max_output_tokens=8192,
|
| 181 |
+
candidate_count=1
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
# Generate content
|
| 185 |
+
response = client.models.generate_content(
|
| 186 |
+
model=model_name,
|
| 187 |
+
contents=prompt,
|
| 188 |
+
config=config
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
# Extract HTML from response
|
| 192 |
+
raw = response.text
|
| 193 |
s, e = raw.find("```html"), raw.rfind("```")
|
| 194 |
html = raw[s+7:e].strip() if s != -1 and e != -1 else raw
|
| 195 |
+
|
| 196 |
return enhance_font_awesome_layout(html)
|
| 197 |
|
| 198 |
def trim_image_whitespace(img: Image.Image, threshold=248, padding=20) -> Image.Image:
|