lastwarning commited on
Commit
b2e50a8
ยท
verified ยท
1 Parent(s): df518dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -22
app.py CHANGED
@@ -570,7 +570,6 @@ def process_uploads(uploaded_files, project_dir):
570
  }, ensure_ascii=False, indent=2), encoding="utf-8")
571
  return "\n".join(messages)
572
 
573
- # FIXED REGEX BUG: Changed (.?) to (.*?) and fixed <> brackets
574
  FILE_BLOCK_PATTERN = re.compile(
575
  r"<<<FILE:\s*(.*?)>>>\s*(.*?)\s*<<<END FILE>>>",
576
  re.DOTALL | re.IGNORECASE,
@@ -650,7 +649,6 @@ def make_html_preview(project_dir):
650
  except Exception as error:
651
  return f"<div style='padding:20px;color:#ff9999'>Preview error: {error}</div>"
652
 
653
- # FIXED INIT BUG
654
  class StopCriteria(StoppingCriteria):
655
  def __init__(self, event):
656
  self.event = event
@@ -854,7 +852,7 @@ def preview_project(conversation_id):
854
 
855
 
856
  # =========================================================
857
- # CHATGPT UI CSS
858
  # =========================================================
859
 
860
  CSS = """
@@ -920,21 +918,16 @@ textarea:focus {
920
  .primary:hover {
921
  background-color: #1a7f64 !important;
922
  }
923
- .message-wrap .message {
924
- border-radius: 8px !important;
925
- padding: 12px 16px !important;
926
- max-width: 85% !important;
927
- margin-bottom: 16px;
928
- }
929
- .user-message {
930
  background-color: #2f2f2f !important;
931
- align-self: flex-end !important;
932
  }
933
- .bot-message {
934
  background-color: #212121 !important;
935
  border: none !important;
936
  }
937
- .bot-message p {
938
  margin: 0;
939
  }
940
  """
@@ -943,7 +936,7 @@ textarea:focus {
943
  # GRADIO APP (CHATGPT LAYOUT)
944
  # =========================================================
945
 
946
- with gr.Blocks(title=APP_NAME, css=CSS) as demo:
947
  conversation_state = gr.State(None)
948
  job_state = gr.State(None)
949
  chat_history_state = gr.State([])
@@ -977,7 +970,6 @@ with gr.Blocks(title=APP_NAME, css=CSS) as demo:
977
  with gr.Column(elem_id="chat-container"):
978
  chatbot = gr.Chatbot(
979
  value=[{"role": "assistant", "content": "Hello! I am ARISE AI. How can I help you with your code today?"}],
980
- type="messages",
981
  height=600,
982
  show_label=False,
983
  show_copy_button=True,
@@ -1032,6 +1024,7 @@ with gr.Blocks(title=APP_NAME, css=CSS) as demo:
1032
  with gr.Row():
1033
  img2img_guidance = gr.Slider(1, 15, value=7.5, step=0.5, label="Guidance")
1034
  img2img_seed = gr.Number(value=0, precision=0, label="Seed")
 
1035
  img2img_button = gr.Button("๐Ÿช„ Transform", variant="primary")
1036
  img2img_output = gr.Image(label="Result", type="pil")
1037
  img2img_seed_output = gr.Number(label="Used Seed", precision=0)
@@ -1044,7 +1037,6 @@ with gr.Blocks(title=APP_NAME, css=CSS) as demo:
1044
  # EVENT HANDLERS
1045
  # =====================================================
1046
 
1047
- # Chat logic
1048
  def chat_and_code(prompt, model_name, max_tokens, temperature, uploaded_files, conversation_id, chat_history, request: gr.Request):
1049
  if not prompt or not prompt.strip():
1050
  yield chat_history, conversation_id, "Waiting for prompt.", None, None, None
@@ -1073,7 +1065,6 @@ with gr.Blocks(title=APP_NAME, css=CSS) as demo:
1073
  outputs=[chatbot, conversation_state, coding_status, project_zip_download, single_file_download, job_state],
1074
  ).then(lambda: "", outputs=code_prompt) # Clear input after send
1075
 
1076
- # History logic
1077
  def load_history_chat(conversation_id, request: gr.Request):
1078
  session_id = request.session_hash if request else "default"
1079
  if not conversation_id:
@@ -1095,7 +1086,6 @@ with gr.Blocks(title=APP_NAME, css=CSS) as demo:
1095
 
1096
  refresh_history_button.click(fn=refresh_history, outputs=history_dropdown)
1097
 
1098
- # New Chat
1099
  new_chat_btn.click(
1100
  fn=lambda: ([{"role": "assistant", "content": "Hello! I am ARISE AI. How can I help you with your code today?"}], None, "Ready for a new conversation.", None),
1101
  outputs=[chatbot, conversation_state, coding_status, job_state]
@@ -1104,7 +1094,6 @@ with gr.Blocks(title=APP_NAME, css=CSS) as demo:
1104
  stop_button.click(fn=stop_job, inputs=job_state, outputs=coding_status)
1105
  preview_button.click(fn=preview_project, inputs=conversation_state, outputs=html_preview)
1106
 
1107
- # Image Gen events
1108
  generate_button.click(
1109
  fn=generate_image,
1110
  inputs=[image_prompt, negative_prompt, image_model, width, height, steps, seed, random_seed],
@@ -1112,7 +1101,7 @@ with gr.Blocks(title=APP_NAME, css=CSS) as demo:
1112
  )
1113
  img2img_button.click(
1114
  fn=generate_image_to_image,
1115
- inputs=[input_image, img2img_prompt, img2img_negative, img2img_model, strength, img2img_steps, img2img_guidance, img2img_seed, random_seed],
1116
  outputs=[img2img_output, img2img_seed_output],
1117
  )
1118
 
@@ -1127,8 +1116,8 @@ if __name__ == "__main__":
1127
  max_size=20,
1128
  ).launch(
1129
  theme=gr.themes.Soft(),
1130
- css=CSS,
1131
- allowed_paths=[str(DATA_DIR.resolve())], # ๐Ÿ‘ˆ FIX: Allowed Paths for Download Error
1132
  show_error=True,
1133
  share=False,
1134
  )
 
570
  }, ensure_ascii=False, indent=2), encoding="utf-8")
571
  return "\n".join(messages)
572
 
 
573
  FILE_BLOCK_PATTERN = re.compile(
574
  r"<<<FILE:\s*(.*?)>>>\s*(.*?)\s*<<<END FILE>>>",
575
  re.DOTALL | re.IGNORECASE,
 
649
  except Exception as error:
650
  return f"<div style='padding:20px;color:#ff9999'>Preview error: {error}</div>"
651
 
 
652
  class StopCriteria(StoppingCriteria):
653
  def __init__(self, event):
654
  self.event = event
 
852
 
853
 
854
  # =========================================================
855
+ # CHATGPT UI CSS (Gradio 6 Compatible)
856
  # =========================================================
857
 
858
  CSS = """
 
918
  .primary:hover {
919
  background-color: #1a7f64 !important;
920
  }
921
+ /* Gradio 6 Chatbot message styling */
922
+ #chatbot-ui .message-row .user {
 
 
 
 
 
923
  background-color: #2f2f2f !important;
924
+ border-radius: 12px !important;
925
  }
926
+ #chatbot-ui .message-row .bot {
927
  background-color: #212121 !important;
928
  border: none !important;
929
  }
930
+ #chatbot-ui .message-row .message p {
931
  margin: 0;
932
  }
933
  """
 
936
  # GRADIO APP (CHATGPT LAYOUT)
937
  # =========================================================
938
 
939
+ with gr.Blocks(title=APP_NAME) as demo:
940
  conversation_state = gr.State(None)
941
  job_state = gr.State(None)
942
  chat_history_state = gr.State([])
 
970
  with gr.Column(elem_id="chat-container"):
971
  chatbot = gr.Chatbot(
972
  value=[{"role": "assistant", "content": "Hello! I am ARISE AI. How can I help you with your code today?"}],
 
973
  height=600,
974
  show_label=False,
975
  show_copy_button=True,
 
1024
  with gr.Row():
1025
  img2img_guidance = gr.Slider(1, 15, value=7.5, step=0.5, label="Guidance")
1026
  img2img_seed = gr.Number(value=0, precision=0, label="Seed")
1027
+ img2img_random = gr.Checkbox(value=True, label="Random")
1028
  img2img_button = gr.Button("๐Ÿช„ Transform", variant="primary")
1029
  img2img_output = gr.Image(label="Result", type="pil")
1030
  img2img_seed_output = gr.Number(label="Used Seed", precision=0)
 
1037
  # EVENT HANDLERS
1038
  # =====================================================
1039
 
 
1040
  def chat_and_code(prompt, model_name, max_tokens, temperature, uploaded_files, conversation_id, chat_history, request: gr.Request):
1041
  if not prompt or not prompt.strip():
1042
  yield chat_history, conversation_id, "Waiting for prompt.", None, None, None
 
1065
  outputs=[chatbot, conversation_state, coding_status, project_zip_download, single_file_download, job_state],
1066
  ).then(lambda: "", outputs=code_prompt) # Clear input after send
1067
 
 
1068
  def load_history_chat(conversation_id, request: gr.Request):
1069
  session_id = request.session_hash if request else "default"
1070
  if not conversation_id:
 
1086
 
1087
  refresh_history_button.click(fn=refresh_history, outputs=history_dropdown)
1088
 
 
1089
  new_chat_btn.click(
1090
  fn=lambda: ([{"role": "assistant", "content": "Hello! I am ARISE AI. How can I help you with your code today?"}], None, "Ready for a new conversation.", None),
1091
  outputs=[chatbot, conversation_state, coding_status, job_state]
 
1094
  stop_button.click(fn=stop_job, inputs=job_state, outputs=coding_status)
1095
  preview_button.click(fn=preview_project, inputs=conversation_state, outputs=html_preview)
1096
 
 
1097
  generate_button.click(
1098
  fn=generate_image,
1099
  inputs=[image_prompt, negative_prompt, image_model, width, height, steps, seed, random_seed],
 
1101
  )
1102
  img2img_button.click(
1103
  fn=generate_image_to_image,
1104
+ inputs=[input_image, img2img_prompt, img2img_negative, img2img_model, strength, img2img_steps, img2img_guidance, img2img_seed, img2img_random],
1105
  outputs=[img2img_output, img2img_seed_output],
1106
  )
1107
 
 
1116
  max_size=20,
1117
  ).launch(
1118
  theme=gr.themes.Soft(),
1119
+ css=CSS, # ๐Ÿ‘ˆ Moved from Blocks to launch
1120
+ allowed_paths=[str(DATA_DIR.resolve())], # ๐Ÿ‘ˆ Fixes Download Error
1121
  show_error=True,
1122
  share=False,
1123
  )