Spaces:
Runtime error
Runtime error
Staticaliza
commited on
Commit
•
cb835d2
1
Parent(s):
b8af554
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
import json
|
4 |
import random
|
@@ -32,6 +33,9 @@ def array_random(array):
|
|
32 |
if not array: return None
|
33 |
return random.choice(array)
|
34 |
|
|
|
|
|
|
|
35 |
def predict(access_key, tokens, instructions, image, pre_input, input, seed = 0):
|
36 |
|
37 |
if (access_key != KEY):
|
@@ -42,7 +46,7 @@ def predict(access_key, tokens, instructions, image, pre_input, input, seed = 0)
|
|
42 |
|
43 |
token = array_random(string_to_json(tokens))
|
44 |
|
45 |
-
formatted_input = instructions.replace(symbol, pre_input) + pre_input + input + "
|
46 |
|
47 |
print(formatted_input)
|
48 |
|
@@ -68,7 +72,8 @@ def maintain_cloud():
|
|
68 |
with gr.Blocks() as demo:
|
69 |
with gr.Row():
|
70 |
with gr.Column():
|
71 |
-
image = gr.Image()
|
|
|
72 |
instructions = gr.Textbox(label="Instruction", placeholder="Message...", value=default_instructions, lines=1)
|
73 |
pre_text = gr.Textbox(label="Pre-Input", placeholder="Message...", value=default_pre_text, lines=1)
|
74 |
text = gr.Textbox(label="Text Input", placeholder="Message...", lines=2)
|
@@ -81,6 +86,7 @@ with gr.Blocks() as demo:
|
|
81 |
run = gr.Button("Generate")
|
82 |
cloud = gr.Button("☁️")
|
83 |
|
|
|
84 |
run.click(predict, inputs=[access_key, json_tokens, instructions, image, pre_text, text, seed], outputs=[output], queue = False)
|
85 |
cloud.click(maintain_cloud, inputs = [], outputs = [output], queue = False)
|
86 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from gradio_client.client import DEFAULT_TEMP_DIR
|
3 |
from huggingface_hub import InferenceClient
|
4 |
import json
|
5 |
import random
|
|
|
33 |
if not array: return None
|
34 |
return random.choice(array)
|
35 |
|
36 |
+
def add_file(file):
|
37 |
+
return file.name, gr.update(label='🖼️ Uploaded!')
|
38 |
+
|
39 |
def predict(access_key, tokens, instructions, image, pre_input, input, seed = 0):
|
40 |
|
41 |
if (access_key != KEY):
|
|
|
46 |
|
47 |
token = array_random(string_to_json(tokens))
|
48 |
|
49 |
+
formatted_input = instructions.replace(symbol, pre_input) + pre_input + input + "![](" + image + ")"
|
50 |
|
51 |
print(formatted_input)
|
52 |
|
|
|
72 |
with gr.Blocks() as demo:
|
73 |
with gr.Row():
|
74 |
with gr.Column():
|
75 |
+
image = gr.Image(type="filepath", label="Image Input", visible=True)
|
76 |
+
upload = gr.UploadButton("Upload Image", file_types=["image"])
|
77 |
instructions = gr.Textbox(label="Instruction", placeholder="Message...", value=default_instructions, lines=1)
|
78 |
pre_text = gr.Textbox(label="Pre-Input", placeholder="Message...", value=default_pre_text, lines=1)
|
79 |
text = gr.Textbox(label="Text Input", placeholder="Message...", lines=2)
|
|
|
86 |
run = gr.Button("Generate")
|
87 |
cloud = gr.Button("☁️")
|
88 |
|
89 |
+
upload.upload(add_file, [upload], [image], queue = False)
|
90 |
run.click(predict, inputs=[access_key, json_tokens, instructions, image, pre_text, text, seed], outputs=[output], queue = False)
|
91 |
cloud.click(maintain_cloud, inputs = [], outputs = [output], queue = False)
|
92 |
|