TA commited on
Commit
534795e
1 Parent(s): f4f1a74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -1,11 +1,20 @@
1
  import gradio as gr
2
  import os
3
  import requests
4
- import json
5
 
6
  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."
7
  TITLE = "Image Prompter"
8
  EXAMPLE_INPUT = "A Reflective cat between stars."
 
 
 
 
 
 
 
 
 
 
9
 
10
  zephyr_7b_beta = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta/"
11
 
@@ -56,11 +65,14 @@ def predict_beta(message, chatbot=[], system_prompt=""):
56
  error_msg = f"Failed to decode response as JSON: {str(e)}"
57
  raise gr.Error(error_msg)
58
 
59
- def chat_interface(message, chat_history):
60
- response = predict_beta(message, chat_history, SYSTEM_PROMPT)
61
  text_start = response.rfind("", ) + len("")
62
  response = response[text_start:]
63
- return response
 
 
 
64
 
65
  welcome_preview_message = f"""
66
  Expand your imagination and broaden your horizons with LLM. Welcome to **{TITLE}**!:\nThis is a chatbot that can generate detailed prompts for image generation models based on simple and short user input.\nSay something like:
@@ -68,5 +80,10 @@ Expand your imagination and broaden your horizons with LLM. Welcome to **{TITLE}
68
  "{EXAMPLE_INPUT}"
69
  """
70
 
71
- chatbot_preview = gr.Chatbot(chat_interface, title=TITLE, system_message=welcome_preview_message)
72
- chatbot_preview.launch()
 
 
 
 
 
 
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
+ import gradio as gr
9
+ import os
10
+ import requests
11
+
12
+ # Include the HTML code for displaying the image
13
+ html_temp = """
14
+ <div style="position: absolute; top: 0; right: 0;">
15
+ <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;'>
16
+ </div>
17
+ """
18
 
19
  zephyr_7b_beta = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta/"
20
 
 
65
  error_msg = f"Failed to decode response as JSON: {str(e)}"
66
  raise gr.Error(error_msg)
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
+
73
+ # Include the image HTML code in the response
74
+ response_with_image = f"{html_temp}\n{response}"
75
+ return response_with_image
76
 
77
  welcome_preview_message = f"""
78
  Expand your imagination and broaden your horizons with LLM. Welcome to **{TITLE}**!:\nThis is a chatbot that can generate detailed prompts for image generation models based on simple and short user input.\nSay something like:
 
80
  "{EXAMPLE_INPUT}"
81
  """
82
 
83
+ # Use the modified test_preview_chatbot function
84
+ chatbot_preview = gr.Chatbot(layout="panel", value=[(None, welcome_preview_message)])
85
+ textbox_preview = gr.Textbox(scale=7, container=False, value=EXAMPLE_INPUT)
86
+
87
+ # Use the modified test_preview_chatbot function
88
+ demo = gr.ChatInterface(test_preview_chatbot, chatbot=chatbot_preview, textbox=textbox_preview)
89
+ demo.launch(share=True)