Omnibus commited on
Commit
03bb47d
1 Parent(s): d0d98e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -7
app.py CHANGED
@@ -1,9 +1,32 @@
1
- from gradio_client import Client
2
  import gradio as gr
3
- client = Client("https://omnibus-html-image-current-tab.hf.space/")
 
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  def get_screenshot(chat: list,height=5000,width=600,chatblock=[1],header=True,theme="light",wait=3000):
6
- result = client.predict(chat,height,width,chatblock,header,theme,wait,api_name="/run_script")
7
  # str in 'Chat: [('user','bot'),('user','bot')]' Textbox component
8
  # float in 'Height' Number component
9
  # float in 'Width' Number component
@@ -26,8 +49,16 @@ chat=[('user','bot'),('user','bot')]
26
 
27
  #get_screenshot(chat=[('user','bot'),('user','bot')])
28
  with gr.Blocks() as app:
29
- inp = gr.Textbox(value=chat)
30
- img=gr.Image(type='filepath')
31
-
32
- app.load(get_screenshot,inp,img)
 
 
 
 
 
 
 
 
33
  app.launch()
 
1
+ from gradio_client import Client, InferenceClient
2
  import gradio as gr
3
+ ss_client = Client("https://omnibus-html-image-current-tab.hf.space/")
4
+ client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
5
 
6
+
7
+ def format_prompt(message, history):
8
+ prompt = "<s>"
9
+ for user_prompt, bot_response in history:
10
+ prompt += f"[INST] {user_prompt} [/INST]"
11
+ prompt += f" {bot_response}</s> "
12
+ prompt += f"[INST] {message} [/INST]"
13
+ return prompt
14
+
15
+
16
+ def chat_inf(system_prompt,prompt,history):
17
+ if not history:
18
+ history = []
19
+ formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
20
+ stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
21
+ output = ""
22
+ for response in stream:
23
+ output += response.token.text
24
+ yield [history,(prompt,output)]
25
+
26
+
27
+
28
  def get_screenshot(chat: list,height=5000,width=600,chatblock=[1],header=True,theme="light",wait=3000):
29
+ result = ss_client.predict(chat,height,width,chatblock,header,theme,wait,api_name="/run_script")
30
  # str in 'Chat: [('user','bot'),('user','bot')]' Textbox component
31
  # float in 'Height' Number component
32
  # float in 'Width' Number component
 
49
 
50
  #get_screenshot(chat=[('user','bot'),('user','bot')])
51
  with gr.Blocks() as app:
52
+ with gr.Row():
53
+ with gr.Column(scale=2):
54
+ chat_b = gr.Chatbot()
55
+ with gr.Column(scale=1)
56
+ with gr.Group():
57
+ inp = gr.Textbox(label="Prompt")
58
+ sys_inp = gr.Textbox(label="System Prompt")
59
+ btn = gr.Button("Chat")
60
+ im_btn=gr.Button("Screenshot")
61
+ img=gr.Image(type='filepath')
62
+ btn.click(chat_inf,[sys_inp,inp,chatbot],chatbot)
63
+ #app.load(get_screenshot,inp,img)
64
  app.launch()