Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -58,7 +58,7 @@ def run_gpt(in_prompt,history,model_drop):
|
|
58 |
return resp
|
59 |
|
60 |
|
61 |
-
def
|
62 |
print (history)
|
63 |
task=None
|
64 |
#if history:
|
@@ -71,23 +71,58 @@ def run(purpose,history,model_drop,chat_drop):
|
|
71 |
#yield ([(purpose,out_prompt)],None)
|
72 |
history.append((purpose,out_prompt))
|
73 |
yield (history,None)
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
#
|
82 |
-
#out=Image.open('tmp.png')
|
83 |
-
r = requests.get(url, stream=True)
|
84 |
-
if r.status_code == 200:
|
85 |
-
out = Image.open(io.BytesIO(r.content))
|
86 |
-
#yield ([(purpose,out_prompt)],out)
|
87 |
-
yield (history,out)
|
88 |
-
else:
|
89 |
-
yield ([(purpose,"an Error occured")],None)
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
################################################
|
92 |
style="""
|
93 |
.top_head{
|
@@ -110,6 +145,8 @@ with gr.Blocks(css=style) as iface:
|
|
110 |
with gr.Row():
|
111 |
with gr.Column(scale=1):
|
112 |
chatbot=gr.Chatbot(show_copy_button=True, layout='panel')
|
|
|
|
|
113 |
msg = gr.Textbox()
|
114 |
model_drop=gr.Dropdown(label="Diffusion Models", type="index", choices=[m for m in models], value=models[0])
|
115 |
chat_model_drop=gr.Dropdown(label="Chatbot Models", type="index", choices=[m for m in chat_models.models], value=chat_models.models[0])
|
|
|
58 |
return resp
|
59 |
|
60 |
|
61 |
+
def generate(purpose,history,model_drop,chat_drop):
|
62 |
print (history)
|
63 |
task=None
|
64 |
#if history:
|
|
|
71 |
#yield ([(purpose,out_prompt)],None)
|
72 |
history.append((purpose,out_prompt))
|
73 |
yield (history,None)
|
74 |
+
|
75 |
+
def describe(purpose,history,model_drop,chat_drop):
|
76 |
+
print (history)
|
77 |
+
task=None
|
78 |
+
#if history:
|
79 |
+
# history=str(history).strip("[]")
|
80 |
+
#if not history:
|
81 |
+
# history = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
+
#action_name, action_input = parse_action(line)
|
84 |
+
out_prompt = run_gpt(purpose,history,model_drop)
|
85 |
+
#yield ([(purpose,out_prompt)],None)
|
86 |
+
history.append((purpose,out_prompt))
|
87 |
+
yield (history,None)
|
88 |
+
|
89 |
+
def run(purpose,history,model_drop,chat_drop,choice):
|
90 |
+
if choice == "Generate":
|
91 |
+
#out_img = infer(out_prompt)
|
92 |
+
out_prompt=generate(purpose,history,model_drop,chat_drop)
|
93 |
+
model=loaded_model[int(model_drop)]
|
94 |
+
out_img=model(out_prompt)
|
95 |
+
print(out_img)
|
96 |
+
url=f'https://johann22-chat-diffusion-describe.hf.space/file={out_img}'
|
97 |
+
print(url)
|
98 |
+
uid = uuid.uuid4()
|
99 |
+
#urllib.request.urlretrieve(image, 'tmp.png')
|
100 |
+
#out=Image.open('tmp.png')
|
101 |
+
r = requests.get(url, stream=True)
|
102 |
+
if r.status_code == 200:
|
103 |
+
out = Image.open(io.BytesIO(r.content))
|
104 |
+
#yield ([(purpose,out_prompt)],out)
|
105 |
+
return (history,out)
|
106 |
+
else:
|
107 |
+
return ([(purpose,"an Error occured")],None)
|
108 |
+
if choice == "Describe":
|
109 |
+
#out_img = infer(out_prompt)
|
110 |
+
out_prompt=describe(purpose,history,model_drop,chat_drop)
|
111 |
+
model=loaded_model[int(model_drop)]
|
112 |
+
out_img=model(out_prompt)
|
113 |
+
print(out_img)
|
114 |
+
url=f'https://johann22-chat-diffusion-describe.hf.space/file={out_img}'
|
115 |
+
print(url)
|
116 |
+
uid = uuid.uuid4()
|
117 |
+
#urllib.request.urlretrieve(image, 'tmp.png')
|
118 |
+
#out=Image.open('tmp.png')
|
119 |
+
r = requests.get(url, stream=True)
|
120 |
+
if r.status_code == 200:
|
121 |
+
out = Image.open(io.BytesIO(r.content))
|
122 |
+
#yield ([(purpose,out_prompt)],out)
|
123 |
+
return (history,out)
|
124 |
+
else:
|
125 |
+
return ([(purpose,"an Error occured")],None)
|
126 |
################################################
|
127 |
style="""
|
128 |
.top_head{
|
|
|
145 |
with gr.Row():
|
146 |
with gr.Column(scale=1):
|
147 |
chatbot=gr.Chatbot(show_copy_button=True, layout='panel')
|
148 |
+
with gr.Row()
|
149 |
+
agent_choice = gr.Radio(choices=["Generate","Describe"])
|
150 |
msg = gr.Textbox()
|
151 |
model_drop=gr.Dropdown(label="Diffusion Models", type="index", choices=[m for m in models], value=models[0])
|
152 |
chat_model_drop=gr.Dropdown(label="Chatbot Models", type="index", choices=[m for m in chat_models.models], value=chat_models.models[0])
|