xhxhdvduenxvxheje commited on
Commit
eb2d37f
1 Parent(s): 779833c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -20
app.py CHANGED
@@ -6,7 +6,6 @@ import os
6
  import subprocess
7
  import sys
8
  import atexit
9
- import time
10
 
11
  API_KEY = os.environ.get("SILICONFLOW_API_KEY")
12
  if not API_KEY:
@@ -20,26 +19,13 @@ HEADERS = {
20
  "Authorization": f"Bearer {API_KEY}"
21
  }
22
 
23
- # Cloudflared 安装和设置
24
- def install_cloudflared():
25
- if sys.platform.startswith('linux'):
26
- subprocess.run(["curl", "-L", "--output", "cloudflared", "https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64"])
27
- subprocess.run(["chmod", "+x", "cloudflared"])
28
- elif sys.platform == 'darwin':
29
- subprocess.run(["brew", "install", "cloudflare/cloudflare/cloudflared"])
30
- elif sys.platform == 'win32':
31
- subprocess.run(["powershell", "-Command", "Invoke-WebRequest -Uri https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe -OutFile cloudflared.exe"])
32
- else:
33
- raise OSError("Unsupported operating system")
34
 
35
  cloudflared_process = None
36
 
37
  def start_cloudflared(port):
38
  global cloudflared_process
39
- if sys.platform.startswith('linux') or sys.platform == 'darwin':
40
- cloudflared_process = subprocess.Popen(["./cloudflared", "tunnel", "--url", f"http://localhost:{port}"])
41
- elif sys.platform == 'win32':
42
- cloudflared_process = subprocess.Popen(["cloudflared.exe", "tunnel", "--url", f"http://localhost:{port}"])
43
  atexit.register(stop_cloudflared)
44
 
45
  def stop_cloudflared():
@@ -48,7 +34,6 @@ def stop_cloudflared():
48
  cloudflared_process.terminate()
49
  cloudflared_process.wait()
50
 
51
- # 其余函数保持不变
52
  def generate_image(model, prompt, image_size, batch_size=1, num_inference_steps=20):
53
  data = {
54
  "model": model,
@@ -83,7 +68,7 @@ def generate_image(model, prompt, image_size, batch_size=1, num_inference_steps=
83
 
84
  def use_gemma_model(prompt, task):
85
  data = {
86
- "model": "google/gemma-2-9b-it",
87
  "messages": [
88
  {"role": "system", "content": f"You are an AI assistant that helps with {task}. Respond concisely."},
89
  {"role": "user", "content": prompt}
@@ -159,8 +144,6 @@ with gr.Blocks() as demo:
159
 
160
  if __name__ == "__main__":
161
  port = 7860 # 或者您想使用的其他端口
162
- print("Installing Cloudflared...")
163
- install_cloudflared()
164
  print("Starting Cloudflared...")
165
  start_cloudflared(port)
166
  print("Cloudflared started. Launching Gradio app...")
 
6
  import subprocess
7
  import sys
8
  import atexit
 
9
 
10
  API_KEY = os.environ.get("SILICONFLOW_API_KEY")
11
  if not API_KEY:
 
19
  "Authorization": f"Bearer {API_KEY}"
20
  }
21
 
22
+ CLOUDFLARED_TOKEN = "eyJhIjoiYmRlYmEzN2E5MzRmOTYwMjM4MjZjMzhjZGU4N2U1NDUiLCJ0IjoiNDI4Mjg3NWEtZmE3Yi00OTNmLTkzMmEtYmUxZDQ3MDUyZDIyIiwicyI6Ik9UVmhNRGt4TldJdE9EazJZaTAwWlRGakxXSXdaREl0WldVeE5UVTBZbVprTUdFdyJ9"
 
 
 
 
 
 
 
 
 
 
23
 
24
  cloudflared_process = None
25
 
26
  def start_cloudflared(port):
27
  global cloudflared_process
28
+ cloudflared_process = subprocess.Popen(["cloudflared", "tunnel", "--url", f"http://localhost:{port}", "run", "--token", CLOUDFLARED_TOKEN])
 
 
 
29
  atexit.register(stop_cloudflared)
30
 
31
  def stop_cloudflared():
 
34
  cloudflared_process.terminate()
35
  cloudflared_process.wait()
36
 
 
37
  def generate_image(model, prompt, image_size, batch_size=1, num_inference_steps=20):
38
  data = {
39
  "model": model,
 
68
 
69
  def use_gemma_model(prompt, task):
70
  data = {
71
+ "model": "Qwen/Qwen2.5-7B-Instruct",
72
  "messages": [
73
  {"role": "system", "content": f"You are an AI assistant that helps with {task}. Respond concisely."},
74
  {"role": "user", "content": prompt}
 
144
 
145
  if __name__ == "__main__":
146
  port = 7860 # 或者您想使用的其他端口
 
 
147
  print("Starting Cloudflared...")
148
  start_cloudflared(port)
149
  print("Cloudflared started. Launching Gradio app...")