TA commited on
Commit
6369161
1 Parent(s): 8048dd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -1,20 +1,22 @@
1
  import gradio as gr
2
  import os
3
  import requests
 
 
 
4
 
5
  SYSTEM_PROMPT = "As an LLM, your job is to generate detailed prompts that start with generate the image, for image generation models based on user input. Be descriptive and specific, but also make sure your prompts are clear and concise."
6
  TITLE = "Image Prompter"
7
- EXAMPLE_INPUT = "A Reflective cat between star."
8
 
9
  html_temp = """
10
  <div style="position: absolute; top: 0; right: 0;">
11
  <img src='https://huggingface.co/spaces/NerdN/open-gpt-Image-Prompter/blob/main/_45a03b4d-ea0f-4b81-873d-ff6b10461d52.jpg' alt='Your Image' style='width:100px;height:100px;'>
12
- <p style="text-align: right;">{}</p>
13
  </div>
14
- <div style="position: absolute; bottom: 0; left: 0;">
15
- <p>Please like the space!</p>
16
  </div>
17
- """.format(EXAMPLE_INPUT)
18
 
19
  zephyr_7b_beta = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta/"
20
 
@@ -25,11 +27,11 @@ def build_input_prompt(message, chatbot, system_prompt):
25
  """
26
  Constructs the input prompt string from the chatbot interactions and the current message.
27
  """
28
- input_prompt = "<|system|>\n" + system_prompt + "</s>\n<|user|>\n"
29
  for interaction in chatbot:
30
- input_prompt = input_prompt + str(interaction[0]) + "</s>\n<|assistant|>\n" + str(interaction[1]) + "\n</s>\n<|user|>\n"
31
 
32
- input_prompt = input_prompt + str(message) + "</s>\n<|assistant|>"
33
  return input_prompt
34
 
35
 
@@ -69,7 +71,7 @@ def predict_beta(message, chatbot=[], system_prompt=""):
69
 
70
  def test_preview_chatbot(message, history):
71
  response = predict_beta(message, history, SYSTEM_PROMPT)
72
- text_start = response.rfind("<|assistant|>", ) + len("<|assistant|>")
73
  response = response[text_start:]
74
  return response
75
 
@@ -80,6 +82,9 @@ Expand your imagination and broaden your horizons with LLM. Welcome to **{TITLE}
80
  "{EXAMPLE_INPUT}"
81
  """
82
 
83
- iface = gr.Interface(fn=test_preview_chatbot, inputs=gr.inputs.Textbox(placeholder=EXAMPLE_INPUT), outputs=gr.outputs.Textbox(), title=TITLE, description=SYSTEM_PROMPT, examples=[EXAMPLE_INPUT], allow_flagging=False, analytics_enabled=False, theme="huggingface")
 
 
 
84
 
85
- iface.launch(share=True)
 
1
  import gradio as gr
2
  import os
3
  import requests
4
+ import gradio as gr
5
+ import os
6
+ import requests
7
 
8
  SYSTEM_PROMPT = "As an LLM, your job is to generate detailed prompts that start with generate the image, for image generation models based on user input. Be descriptive and specific, but also make sure your prompts are clear and concise."
9
  TITLE = "Image Prompter"
10
+ EXAMPLE_INPUT = "A Reflective cat between stars."
11
 
12
  html_temp = """
13
  <div style="position: absolute; top: 0; right: 0;">
14
  <img src='https://huggingface.co/spaces/NerdN/open-gpt-Image-Prompter/blob/main/_45a03b4d-ea0f-4b81-873d-ff6b10461d52.jpg' alt='Your Image' style='width:100px;height:100px;'>
 
15
  </div>
16
+ <div style="position: absolute; bottom: 0; left: 0; padding: 10px;">
17
+ <p>{EXAMPLE_INPUT}</p>
18
  </div>
19
+ """
20
 
21
  zephyr_7b_beta = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta/"
22
 
 
27
  """
28
  Constructs the input prompt string from the chatbot interactions and the current message.
29
  """
30
+ input_prompt = "\n" + system_prompt + "</s>\n\n"
31
  for interaction in chatbot:
32
+ input_prompt = input_prompt + str(interaction[0]) + "</s>\n\n" + str(interaction[1]) + "\n</s>\n\n"
33
 
34
+ input_prompt = input_prompt + str(message) + "</s>\n"
35
  return input_prompt
36
 
37
 
 
71
 
72
  def test_preview_chatbot(message, history):
73
  response = predict_beta(message, history, SYSTEM_PROMPT)
74
+ text_start = response.rfind("", ) + len("")
75
  response = response[text_start:]
76
  return response
77
 
 
82
  "{EXAMPLE_INPUT}"
83
  """
84
 
85
+ chatbot_preview = gr.Chatbot(layout="panel", value=[(None, welcome_preview_message)])
86
+ textbox_preview = gr.Textbox(scale=7, container=False, value=EXAMPLE_INPUT)
87
+
88
+ demo = gr.ChatInterface(test_preview_chatbot, chatbot=chatbot_preview, textbox=textbox_preview, examples=[[EXAMPLE_INPUT]])
89
 
90
+ demo.launch(share=True)