NerdN commited on
Commit
d75bf46
1 Parent(s): 316b18c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -12
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import gradio as gr
3
  import os
4
  import requests
@@ -76,18 +75,43 @@ def test_preview_chatbot(message, history):
76
  response = predict_beta(message, history, SYSTEM_PROMPT)
77
  return response
78
 
79
- welcome_preview_message = f"""
80
- 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.\nTry one of these prompts:
 
 
 
 
81
 
82
- - "{EXAMPLE_INPUTS[0]['prompt']}"
83
- - "{EXAMPLE_INPUTS[1]['prompt']}"
84
- - "{EXAMPLE_INPUTS[2]['prompt']}"
85
- - "{EXAMPLE_INPUTS[3]['prompt']}"
86
- """
 
 
87
 
88
- chatbot_preview = gr.Chatbot(layout="panel", value=[(None, welcome_preview_message)])
89
- textbox_preview = gr.Textbox(scale=7, container=False, value=EXAMPLE_INPUTS[0]['prompt'])
 
 
90
 
91
- demo = gr.ChatInterface(test_preview_chatbot, chatbot=chatbot_preview, textbox=textbox_preview, examples=[[EXAMPLE_INPUTS[0]['prompt']]])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
- demo.launch(share=True)
 
 
1
  import gradio as gr
2
  import os
3
  import requests
 
75
  response = predict_beta(message, history, SYSTEM_PROMPT)
76
  return response
77
 
78
+ # Create a Gradio custom component for image and prompt
79
+ class ImagePromptComponent(gr.Component):
80
+ def __init__(self, image_url, prompt):
81
+ self.image_url = image_url
82
+ self.prompt = prompt
83
+ super().__init__()
84
 
85
+ def to_html(self):
86
+ return f"""
87
+ <div>
88
+ <img src='{self.image_url}' alt='Image' style='width:100px;height:100px;'>
89
+ <p>{self.prompt}</p>
90
+ </div>
91
+ """
92
 
93
+ # Generate instances of the custom component
94
+ image_prompt_components = [
95
+ ImagePromptComponent(EXAMPLE_INPUTS[i]['image_url'], EXAMPLE_INPUTS[i]['prompt']) for i in range(4)
96
+ ]
97
 
98
+ # Display HTML and launch the interface
99
+ gr.Interface(
100
+ fn=test_preview_chatbot,
101
+ live=False,
102
+ examples=[[EXAMPLE_INPUTS[0]['prompt']]],
103
+ inputs=image_prompt_components,
104
+ outputs=gr.Textbox(),
105
+ layout="vertical",
106
+ html=html_temp.format(
107
+ image_url_1=image_prompt_components[0].image_url,
108
+ prompt_1=image_prompt_components[0].prompt,
109
+ image_url_2=image_prompt_components[1].image_url,
110
+ prompt_2=image_prompt_components[1].prompt,
111
+ image_url_3=image_prompt_components[2].image_url,
112
+ prompt_3=image_prompt_components[2].prompt,
113
+ image_url_4=image_prompt_components[3].image_url,
114
+ prompt_4=image_prompt_components[3].prompt,
115
+ ),
116
+ ).launch(share=True)
117