Revolution-D commited on
Commit
e2a69de
·
verified ·
1 Parent(s): ef0a146

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -8,7 +8,7 @@ API_KEY = "d72ef10876b9403a9479c6e31f27a4be".strip()
8
  WORKFLOW_ID = "1958842411961233410"
9
  UPLOAD_URL = "https://www.runninghub.cn/task/openapi/upload"
10
  CREATE_TASK_URL = "https://www.runninghub.cn/task/openapi/create"
11
- GET_TASK_INFO_URL = "https://www.runninghub.ai/task/openapi/getTaskInfo" # 修正了網址
12
  HEADERS = {"Host": "www.runninghub.cn"}
13
 
14
  # 工作流節點 ID
@@ -17,7 +17,11 @@ POSITIVE_PROMPT_NODE_ID = "144"
17
  SEED_NODE_ID = "132"
18
 
19
  # --- 核心函式 ---
20
- def process_image_workflow(image_path, positive_prompt, seed=-1):
 
 
 
 
21
  if image_path is None:
22
  return "請先上傳圖片!", None
23
 
@@ -66,7 +70,7 @@ def process_image_workflow(image_path, positive_prompt, seed=-1):
66
  return f"任務建立連線錯誤: {e}", None
67
 
68
  # --- 步驟 3: 輪詢任務狀態 ---
69
- max_retries = 40 # 增加重試次數以應對長任務
70
  retry_interval = 5
71
 
72
  for i in range(max_retries):
@@ -76,12 +80,11 @@ def process_image_workflow(image_path, positive_prompt, seed=-1):
76
  status_payload = {"apiKey": API_KEY, "taskId": task_id}
77
  status_response = requests.post(GET_TASK_INFO_URL, headers={"Content-Type": "application/json"}, data=json.dumps(status_payload))
78
 
79
- # 檢查 HTTP 狀態碼
80
  if status_response.status_code == 404:
81
  print("Task not found yet, retrying...")
82
- continue # 繼續下一次迴圈
83
 
84
- status_response.raise_for_status() # 如果不是 200 或 404,則拋出錯誤
85
  status_data = status_response.json()
86
  print("查詢回傳:", status_data)
87
 
@@ -114,21 +117,21 @@ def process_image_workflow(image_path, positive_prompt, seed=-1):
114
  # --- Gradio 介面 ---
115
  with gr.Blocks() as demo:
116
  gr.Markdown("# RunningHub 工作流圖生圖")
117
- gr.Markdown("上傳圖片,輸入正向提示詞與種子值,啟動遠端工作流任務。")
118
 
119
  with gr.Row():
120
  with gr.Column():
121
  image_input = gr.Image(type="filepath", label="上傳圖片")
122
- prompt_input = gr.Textbox(lines=3, label="正向提示詞 (Positive Prompt)", placeholder="輸入你想生成的內容...")
123
  seed_input = gr.Number(label="種子值 (Seed)", value=-1, precision=0)
124
  process_button = gr.Button("開始處理圖像")
125
  with gr.Column():
126
  status_output = gr.Textbox(label="任務狀態", interactive=False)
127
  image_output = gr.Image(label="生成圖片")
128
 
 
129
  process_button.click(
130
  fn=process_image_workflow,
131
- inputs=[image_input, prompt_input, seed_input],
132
  outputs=[status_output, image_output]
133
  )
134
 
 
8
  WORKFLOW_ID = "1958842411961233410"
9
  UPLOAD_URL = "https://www.runninghub.cn/task/openapi/upload"
10
  CREATE_TASK_URL = "https://www.runninghub.cn/task/openapi/create"
11
+ GET_TASK_INFO_URL = "https://www.runninghub.ai/task/openapi/getTaskInfo"
12
  HEADERS = {"Host": "www.runninghub.cn"}
13
 
14
  # 工作流節點 ID
 
17
  SEED_NODE_ID = "132"
18
 
19
  # --- 核心函式 ---
20
+ # 移除 positive_prompt 參數
21
+ def process_image_workflow(image_path, seed=-1):
22
+ # 在這裡設定固定的提示詞
23
+ positive_prompt = "a charming young woman with bright eyes and a subtle smile"
24
+
25
  if image_path is None:
26
  return "請先上傳圖片!", None
27
 
 
70
  return f"任務建立連線錯誤: {e}", None
71
 
72
  # --- 步驟 3: 輪詢任務狀態 ---
73
+ max_retries = 40
74
  retry_interval = 5
75
 
76
  for i in range(max_retries):
 
80
  status_payload = {"apiKey": API_KEY, "taskId": task_id}
81
  status_response = requests.post(GET_TASK_INFO_URL, headers={"Content-Type": "application/json"}, data=json.dumps(status_payload))
82
 
 
83
  if status_response.status_code == 404:
84
  print("Task not found yet, retrying...")
85
+ continue
86
 
87
+ status_response.raise_for_status()
88
  status_data = status_response.json()
89
  print("查詢回傳:", status_data)
90
 
 
117
  # --- Gradio 介面 ---
118
  with gr.Blocks() as demo:
119
  gr.Markdown("# RunningHub 工作流圖生圖")
120
+ gr.Markdown("上傳圖片,輸入種子值,啟動遠端工作流任務。")
121
 
122
  with gr.Row():
123
  with gr.Column():
124
  image_input = gr.Image(type="filepath", label="上傳圖片")
 
125
  seed_input = gr.Number(label="種子值 (Seed)", value=-1, precision=0)
126
  process_button = gr.Button("開始處理圖像")
127
  with gr.Column():
128
  status_output = gr.Textbox(label="任務狀態", interactive=False)
129
  image_output = gr.Image(label="生成圖片")
130
 
131
+ # 移除 inputs=[..., prompt_input, ...]
132
  process_button.click(
133
  fn=process_image_workflow,
134
+ inputs=[image_input, seed_input],
135
  outputs=[status_output, image_output]
136
  )
137