Xilixmeaty40 commited on
Commit
e4e7802
·
verified ·
1 Parent(s): 5bee02b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -3,7 +3,7 @@ from gradio_client import Client
3
  from huggingface_hub import InferenceClient
4
  import random
5
 
6
- ss_client = Client("")
7
 
8
  with open("models.txt", "r") as file:
9
  models = file.read().splitlines()
@@ -72,6 +72,14 @@ def chat_inf(system_prompt, prompt, history, memory, client_choice, seed, temp,
72
  print(f"Error during model inference: {e}")
73
  yield [("Error", "The model failed to respond, possibly due to a timeout. Please try again.")], memory
74
 
 
 
 
 
 
 
 
 
75
  def clear_fn():
76
  return None, None, None, None
77
 
@@ -99,7 +107,7 @@ with gr.Blocks() as app:
99
  with gr.Column(scale=1):
100
  stop_btn = gr.Button("Stop")
101
  clear_btn = gr.Button("Clear")
102
- client_choice = gr.Dropdown(label="Models", type='index', choices=[c for c in models], value=models[0], interactive=True)
103
  with gr.Column(scale=1):
104
  rand = gr.Checkbox(label="Random Seed", value=True)
105
  seed = gr.Slider(label="Seed", minimum=1, maximum=1111111111111111, step=1, value=rand_val)
@@ -108,9 +116,19 @@ with gr.Blocks() as app:
108
  top_p = gr.Slider(label="Top-P", step=0.01, minimum=0.01, maximum=1.0, value=0.49)
109
  rep_p = gr.Slider(label="Repetition Penalty", step=0.01, minimum=0.1, maximum=2.0, value=0.99)
110
  chat_mem = gr.Number(label="Chat Memory", value=4)
 
 
 
 
 
 
 
 
 
111
  rand.change(check_rand, inputs=[rand, seed], outputs=seed)
112
  btn.click(chat_inf, inputs=[sys_inp, inp, chat_b, memory, client_choice, seed, temp, tokens, top_p, rep_p, chat_mem, custom_prompt], outputs=[chat_b, memory])
113
  stop_btn.click(lambda: None, [], chat_b.stop)
114
  clear_btn.click(clear_fn, [], [inp, sys_inp, chat_b, memory])
 
115
 
116
  app.launch()
 
3
  from huggingface_hub import InferenceClient
4
  import random
5
 
6
+ ss_client = Client("https://xilixmeaty40-html-image-current-tabx.hf.space/")
7
 
8
  with open("models.txt", "r") as file:
9
  models = file.read().splitlines()
 
72
  print(f"Error during model inference: {e}")
73
  yield [("Error", "The model failed to respond, possibly due to a timeout. Please try again.")], memory
74
 
75
+ def get_screenshot(chat, height=5000, width=600, chatblock=[], theme="light", wait=3000, header=True):
76
+ tog = 0
77
+ if chatblock:
78
+ tog = 3
79
+ result = ss_client.predict(str(chat), height, width, chatblock, header, theme, wait, api_name="/run_script")
80
+ out = f'https://xilixmeaty40-html-image-current-tabx.hf.space/file={result[tog]}'
81
+ return out
82
+
83
  def clear_fn():
84
  return None, None, None, None
85
 
 
107
  with gr.Column(scale=1):
108
  stop_btn = gr.Button("Stop")
109
  clear_btn = gr.Button("Clear")
110
+ client_choice = gr.Dropdown(label="Models", type='index', choices=[c for c in models if c in [client.model_id for client in clients]], value=models[0], interactive=True)
111
  with gr.Column(scale=1):
112
  rand = gr.Checkbox(label="Random Seed", value=True)
113
  seed = gr.Slider(label="Seed", minimum=1, maximum=1111111111111111, step=1, value=rand_val)
 
116
  top_p = gr.Slider(label="Top-P", step=0.01, minimum=0.01, maximum=1.0, value=0.49)
117
  rep_p = gr.Slider(label="Repetition Penalty", step=0.01, minimum=0.1, maximum=2.0, value=0.99)
118
  chat_mem = gr.Number(label="Chat Memory", value=4)
119
+ with gr.Accordion(label="Screenshot", open=False):
120
+ im_btn = gr.Button("Screenshot")
121
+ img = gr.Image(type='filepath')
122
+ im_height = gr.Number(label="Height", value=5000)
123
+ im_width = gr.Number(label="Width", value=500)
124
+ wait_time = gr.Number(label="Wait Time", value=3000)
125
+ theme = gr.Radio(label="Theme", choices=["light", "dark"], value="light")
126
+ chatblock = gr.Dropdown(label="Chatblocks", choices=[c for c in range(0, 21)], value=0, type="index")
127
+ header = gr.Checkbox(label="Include header?", value=True)
128
  rand.change(check_rand, inputs=[rand, seed], outputs=seed)
129
  btn.click(chat_inf, inputs=[sys_inp, inp, chat_b, memory, client_choice, seed, temp, tokens, top_p, rep_p, chat_mem, custom_prompt], outputs=[chat_b, memory])
130
  stop_btn.click(lambda: None, [], chat_b.stop)
131
  clear_btn.click(clear_fn, [], [inp, sys_inp, chat_b, memory])
132
+ im_btn.click(get_screenshot, inputs=[chat_b, im_height, im_width, chatblock, theme, wait_time, header], outputs=img)
133
 
134
  app.launch()