tomo2chin2 commited on
Commit
e780bc9
·
verified ·
1 Parent(s): 6c102df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -28,7 +28,7 @@ class GeminiRequest(BaseModel):
28
  """Geminiへのリクエストデータモデル"""
29
  text: str
30
  extension_percentage: float = 6.0 # デフォルト値6%
31
- temperature: float = 1.0 # デフォルト値1.0の温度パラメータ
32
  trim_whitespace: bool = True # 余白トリミングオプション(デフォルト有効)
33
 
34
  class ScreenshotRequest(BaseModel):
@@ -107,7 +107,7 @@ def enhance_font_awesome_layout(html_code):
107
  # どちらもない場合は先頭に追加
108
  return f'<html><head>{fa_fix_css}</head>' + html_code + '</html>'
109
 
110
- def generate_html_from_text(text, temperature=1.0):
111
  """テキストからHTMLを生成する"""
112
  try:
113
  # APIキーの取得と設定
@@ -244,12 +244,14 @@ def generate_html_from_text(text, temperature=1.0):
244
  logger.warning(f"{model_name}が利用できません: {e}, フォールバックモデル{fallback_model}を使用します")
245
  model = genai.GenerativeModel(fallback_model)
246
 
247
- # 生成設定
248
  generation_config = {
249
- "temperature": temperature, # パラメータとして受け取った温度を設定
250
- "top_p": 0.95,
251
- "top_k": 64,
252
  "max_output_tokens": 8192,
 
 
253
  }
254
 
255
  # プロンプト構築
@@ -659,7 +661,7 @@ def render_fullpage_screenshot(html_code: str, extension_percentage: float = 6.0
659
  logger.error(f"Error removing temporary file {tmp_path}: {e}")
660
 
661
  # --- Geminiを使った新しい関数 ---
662
- def text_to_screenshot(text: str, extension_percentage: float, temperature: float = 1.0, trim_whitespace: bool = True) -> Image.Image:
663
  """テキストをGemini APIでHTMLに変換し、スクリーンショットを生成する統合関数"""
664
  try:
665
  # 1. テキストからHTMLを生成(温度パラメータも渡す)
@@ -825,13 +827,13 @@ with gr.Blocks(title="Full Page Screenshot (テキスト変換対応)", theme=gr
825
  label="上下高さ拡張率(%)"
826
  )
827
 
828
- # 温度調整スライダー(テキストモード時のみ表示)
829
  temperature = gr.Slider(
830
  minimum=0.0,
831
- maximum=1.4,
832
  step=0.1,
833
- value=1.0, # デフォルト値1.0
834
- label="生成時の温度(創造性)",
835
  visible=False # 最初は非表示
836
  )
837
 
@@ -872,6 +874,7 @@ with gr.Blocks(title="Full Page Screenshot (テキスト変換対応)", theme=gr
872
 
873
  ## 設定情報
874
  - 使用モデル: {gemini_model} (環境変数 GEMINI_MODEL で変更可能)
 
875
  """)
876
 
877
  # --- Mount Gradio App onto FastAPI ---
 
28
  """Geminiへのリクエストデータモデル"""
29
  text: str
30
  extension_percentage: float = 6.0 # デフォルト値6%
31
+ temperature: float = 0.3 # デフォルト値を0.3に下げて創造性を抑制
32
  trim_whitespace: bool = True # 余白トリミングオプション(デフォルト有効)
33
 
34
  class ScreenshotRequest(BaseModel):
 
107
  # どちらもない場合は先頭に追加
108
  return f'<html><head>{fa_fix_css}</head>' + html_code + '</html>'
109
 
110
+ def generate_html_from_text(text, temperature=0.3):
111
  """テキストからHTMLを生成する"""
112
  try:
113
  # APIキーの取得と設定
 
244
  logger.warning(f"{model_name}が利用できません: {e}, フォールバックモデル{fallback_model}を使用します")
245
  model = genai.GenerativeModel(fallback_model)
246
 
247
+ # 生成設定 - 一貫性を重視した設定に変更
248
  generation_config = {
249
+ "temperature": temperature, # 低い温度で創造性を抑制
250
+ "top_p": 0.7, # 0.95から0.7に下げて出力の多様性を制限
251
+ "top_k": 20, # 64から20に下げて候補を絞る
252
  "max_output_tokens": 8192,
253
+ "candidate_count": 1, # 候補は1つだけ生成
254
+ "seed": 42, # 固定シードを使用して再現性を高める
255
  }
256
 
257
  # プロンプト構築
 
661
  logger.error(f"Error removing temporary file {tmp_path}: {e}")
662
 
663
  # --- Geminiを使った新しい関数 ---
664
+ def text_to_screenshot(text: str, extension_percentage: float, temperature: float = 0.3, trim_whitespace: bool = True) -> Image.Image:
665
  """テキストをGemini APIでHTMLに変換し、スクリーンショットを生成する統合関数"""
666
  try:
667
  # 1. テキストからHTMLを生成(温度パラメータも渡す)
 
827
  label="上下高さ拡張率(%)"
828
  )
829
 
830
+ # 温度調整スライダー(テキストモード時のみ表示)- デフォルト値と説明を変更
831
  temperature = gr.Slider(
832
  minimum=0.0,
833
+ maximum=1.0, # 上限値を1.4から1.0に変更
834
  step=0.1,
835
+ value=0.3, # デフォルト値を0.3に変更
836
+ label="生成時の温度(低い=一貫性高、高い=創造性高)",
837
  visible=False # 最初は非表示
838
  )
839
 
 
874
 
875
  ## 設定情報
876
  - 使用モデル: {gemini_model} (環境変数 GEMINI_MODEL で変更可能)
877
+ - 生成設定: 固定シード値(42)を使用して結果の一貫性を確保
878
  """)
879
 
880
  # --- Mount Gradio App onto FastAPI ---