TA commited on
Commit
0229f11
·
1 Parent(s): a8ae245

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -44
app.py CHANGED
@@ -4,33 +4,8 @@ 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_INPUTS = [
8
- {"prompt": "A Reflective cat between stars.", "image_url": "https://www.bing.com/images/create/a-black-cat-with-a-shiny2c-reflective-coat-is-float/1-656c50e048424f578a489a4875acd14f?id=%2b0DNSc2C8Sw26e32dIzHZA%3d%3d&view=detailv2&idpp=genimg&idpclose=1&FORM=SYDBIC"},
9
- {"prompt": "A Stunning sunset over the mountains.", "image_url": "https://www.example.com/sunset_image.jpg"},
10
- {"prompt": "An Enchanted forest with fireflies.", "image_url": "https://www.example.com/forest_image.jpg"},
11
- {"prompt": "A Mysterious spaceship in the night sky.", "image_url": "https://www.example.com/spaceship_image.jpg"}
12
- ]
13
-
14
- html_temp = """
15
- <div style="display: flex; justify-content: space-between; padding: 10px;">
16
- <div>
17
- <img src='{image_url_1}' alt='Image 1' style='width:100px;height:100px;'>
18
- <p>{prompt_1}</p>
19
- </div>
20
- <div>
21
- <img src='{image_url_2}' alt='Image 2' style='width:100px;height:100px;'>
22
- <p>{prompt_2}</p>
23
- </div>
24
- <div>
25
- <img src='{image_url_3}' alt='Image 3' style='width:100px;height:100px;'>
26
- <p>{prompt_3}</p>
27
- </div>
28
- <div>
29
- <img src='{image_url_4}' alt='Image 4' style='width:100px;height:100px;'>
30
- <p>{prompt_4}</p>
31
- </div>
32
- </div>
33
- """
34
 
35
  zephyr_7b_beta = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta/"
36
 
@@ -59,7 +34,7 @@ def predict_beta(message, chatbot=[], system_prompt=""):
59
  bot_message = json_obj['generated_text']
60
  return bot_message
61
  elif 'error' in json_obj:
62
- raise gr.Error(json_obj['error'] + ' Please refresh and try again with smaller input prompt')
63
  else:
64
  warning_msg = f"Unexpected response: {json_obj}"
65
  raise gr.Error(warning_msg)
@@ -72,25 +47,14 @@ def predict_beta(message, chatbot=[], system_prompt=""):
72
 
73
  def test_preview_chatbot(message, history):
74
  response = predict_beta(message, history, SYSTEM_PROMPT)
75
- return response
76
 
77
- # Display HTML and launch the interface
78
  gr.Interface(
79
  fn=test_preview_chatbot,
80
  live=False,
81
- examples=[[EXAMPLE_INPUTS[0]['prompt']]],
82
- inputs=gr.Textbox(scale=7, container=False, value=EXAMPLE_INPUTS[0]['prompt']),
83
- outputs=gr.Text(type="html"),
84
- layout="vertical",
85
- html=html_temp.format(
86
- image_url_1=EXAMPLE_INPUTS[0]["image_url"],
87
- prompt_1=EXAMPLE_INPUTS[0]["prompt"],
88
- image_url_2=EXAMPLE_INPUTS[1]["image_url"],
89
- prompt_2=EXAMPLE_INPUTS[1]["prompt"],
90
- image_url_3=EXAMPLE_INPUTS[2]["image_url"],
91
- prompt_3=EXAMPLE_INPUTS[2]["prompt"],
92
- image_url_4=EXAMPLE_INPUTS[3]["image_url"],
93
- prompt_4=EXAMPLE_INPUTS[3]["prompt"],
94
- ),
95
  ).launch(share=True)
96
 
 
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_PROMPT = "A Reflective cat between stars."
8
+ EXAMPLE_IMAGE_URL = "https://www.bing.com/images/create/a-black-cat-with-a-shiny2c-reflective-coat-is-float/1-656c50e048424f578a489a4875acd14f?id=%2b0DNSc2C8Sw26e32dIzHZA%3d%3d&view=detailv2&idpp=genimg&idpclose=1&FORM=SYDBIC"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  zephyr_7b_beta = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta/"
11
 
 
34
  bot_message = json_obj['generated_text']
35
  return bot_message
36
  elif 'error' in json_obj:
37
+ raise gr.Error(json_obj['error'] + ' Please refresh and try again with a smaller input prompt')
38
  else:
39
  warning_msg = f"Unexpected response: {json_obj}"
40
  raise gr.Error(warning_msg)
 
47
 
48
  def test_preview_chatbot(message, history):
49
  response = predict_beta(message, history, SYSTEM_PROMPT)
50
+ return response, EXAMPLE_IMAGE_URL
51
 
52
+ # Launch the interface
53
  gr.Interface(
54
  fn=test_preview_chatbot,
55
  live=False,
56
+ examples=[[EXAMPLE_PROMPT]],
57
+ inputs=gr.Textbox(scale=7, container=False, value=EXAMPLE_PROMPT),
58
+ outputs=[gr.Textbox(), gr.Image()],
 
 
 
 
 
 
 
 
 
 
 
59
  ).launch(share=True)
60