Spaces:
Runtime error
Runtime error
TA
commited on
Commit
·
d75bf46
1
Parent(s):
316b18c
Update app.py
Browse files
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 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
| 90 |
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|
|
|