TA commited on
Commit
edf2a04
1 Parent(s): ebe55ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -1,18 +1,15 @@
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 stars."
 
 
 
8
 
9
  html_temp = """
10
- <div style="text-align: center;">
11
- <h1>{}</h1>
12
- <img src='https://huggingface.co/spaces/NerdN/open-gpt-Image-Prompter/blob/main/_45a03b4d-ea0f-4b81-873d-ff6b10461d52.jpg' alt='Your Image' style='width:300px;height:300px;'>
13
- <p>{}</p>
14
  </div>
15
- """.format(TITLE, EXAMPLE_INPUT)
16
 
17
  zephyr_7b_beta = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta/"
18
 
@@ -23,11 +20,11 @@ def build_input_prompt(message, chatbot, system_prompt):
23
  """
24
  Constructs the input prompt string from the chatbot interactions and the current message.
25
  """
26
- input_prompt = "\n" + system_prompt + "</s>\n\n"
27
  for interaction in chatbot:
28
- input_prompt = input_prompt + str(interaction[0]) + "</s>\n\n" + str(interaction[1]) + "\n</s>\n\n"
29
 
30
- input_prompt = input_prompt + str(message) + "</s>\n"
31
  return input_prompt
32
 
33
 
@@ -67,7 +64,7 @@ def predict_beta(message, chatbot=[], system_prompt=""):
67
 
68
  def test_preview_chatbot(message, history):
69
  response = predict_beta(message, history, SYSTEM_PROMPT)
70
- text_start = response.rfind("", ) + len("")
71
  response = response[text_start:]
72
  return response
73
 
@@ -81,6 +78,7 @@ Expand your imagination and broaden your horizons with LLM. Welcome to **{TITLE}
81
  chatbot_preview = gr.Chatbot(layout="panel", value=[(None, welcome_preview_message)])
82
  textbox_preview = gr.Textbox(scale=7, container=False, value=EXAMPLE_INPUT)
83
 
84
- demo = gr.ChatInterface(test_preview_chatbot, chatbot=chatbot_preview, textbox=textbox_preview, title=None, html=html_temp)
 
85
 
86
- demo.launch(share=True)
 
 
 
 
 
1
  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."
2
  TITLE = "Image Prompter"
3
  EXAMPLE_INPUT = "A Reflective cat between stars."
4
+ import gradio as gr
5
+ import os
6
+ import requests
7
 
8
  html_temp = """
9
+ <div style="position: absolute; top: 0; right: 0;">
10
+ <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;'>
 
 
11
  </div>
12
+ """
13
 
14
  zephyr_7b_beta = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta/"
15
 
 
20
  """
21
  Constructs the input prompt string from the chatbot interactions and the current message.
22
  """
23
+ input_prompt = "<|system|>\n" + system_prompt + "</s>\n<|user|>\n"
24
  for interaction in chatbot:
25
+ input_prompt = input_prompt + str(interaction[0]) + "</s>\n<|assistant|>\n" + str(interaction[1]) + "\n</s>\n<|user|>\n"
26
 
27
+ input_prompt = input_prompt + str(message) + "</s>\n<|assistant|>"
28
  return input_prompt
29
 
30
 
 
64
 
65
  def test_preview_chatbot(message, history):
66
  response = predict_beta(message, history, SYSTEM_PROMPT)
67
+ text_start = response.rfind("<|assistant|>", ) + len("<|assistant|>")
68
  response = response[text_start:]
69
  return response
70
 
 
78
  chatbot_preview = gr.Chatbot(layout="panel", value=[(None, welcome_preview_message)])
79
  textbox_preview = gr.Textbox(scale=7, container=False, value=EXAMPLE_INPUT)
80
 
81
+ demo = gr.ChatInterface(test_preview_chatbot, chatbot=chatbot_preview, textbox=textbox_preview)
82
+
83
 
84
+ demo.launch(share=True)