Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -165,20 +165,24 @@ with st.sidebar.expander("tasks documentation"):
|
|
165 |
|
166 |
# functions ########################################
|
167 |
cwd = os.getcwd()
|
168 |
-
def get_input(upload,text):
|
169 |
if upload is not None:
|
170 |
return upload
|
171 |
-
|
172 |
-
|
173 |
-
|
|
|
|
|
|
|
|
|
174 |
|
175 |
def display_inputs(task):
|
176 |
-
if dict_hg_tasks_params[task]["input"] == "upload":
|
177 |
-
return st.file_uploader("Choose a file"),""
|
178 |
elif dict_hg_tasks_params[task]["input"] == "text":
|
179 |
-
return None,st.text_input("Enter a text")
|
180 |
else:
|
181 |
-
return None,""
|
182 |
|
183 |
def display_prompt(task):
|
184 |
if dict_hg_tasks_params[task]["prompt"] is True:
|
@@ -196,14 +200,14 @@ if selected_task :
|
|
196 |
response = None
|
197 |
task = dict_hg_tasks[selected_task]
|
198 |
if model:
|
199 |
-
client = InferenceClient(model=model
|
200 |
else:
|
201 |
-
client = InferenceClient(
|
202 |
-
uploaded_input,text_input = display_inputs(task)
|
203 |
prompt_input = display_prompt(task)
|
204 |
context_input = display_context(task)
|
205 |
-
if get_input(uploaded_input,text_input):
|
206 |
-
input = get_input(uploaded_input,text_input)
|
207 |
response = getattr(client, task)(input)
|
208 |
elif prompt_input:
|
209 |
if context_input is not None:
|
@@ -228,5 +232,4 @@ if selected_task :
|
|
228 |
elif dict_hg_tasks_params[task]["output"] == "image":
|
229 |
response.save(os.path.join(cwd,"generated_image.png"))
|
230 |
image = Image.open(os.path.join(cwd,"generated_image.png"))
|
231 |
-
st.image(image)
|
232 |
-
|
|
|
165 |
|
166 |
# functions ########################################
|
167 |
cwd = os.getcwd()
|
168 |
+
def get_input(upload,url,text):
|
169 |
if upload is not None:
|
170 |
return upload
|
171 |
+
else:
|
172 |
+
if url:
|
173 |
+
print(url)
|
174 |
+
return url
|
175 |
+
elif text:
|
176 |
+
return text
|
177 |
+
return None # Default return if neither upload nor url is provided
|
178 |
|
179 |
def display_inputs(task):
|
180 |
+
if dict_hg_tasks_params[task]["input"] == "upload,url":
|
181 |
+
return st.file_uploader("Choose a file"),st.text_input("or enter a file url"),""
|
182 |
elif dict_hg_tasks_params[task]["input"] == "text":
|
183 |
+
return None,"",st.text_input("Enter a text")
|
184 |
else:
|
185 |
+
return None,"",""
|
186 |
|
187 |
def display_prompt(task):
|
188 |
if dict_hg_tasks_params[task]["prompt"] is True:
|
|
|
200 |
response = None
|
201 |
task = dict_hg_tasks[selected_task]
|
202 |
if model:
|
203 |
+
client = InferenceClient(model=model)
|
204 |
else:
|
205 |
+
client = InferenceClient()
|
206 |
+
uploaded_input,url_input,text_input = display_inputs(task)
|
207 |
prompt_input = display_prompt(task)
|
208 |
context_input = display_context(task)
|
209 |
+
if get_input(uploaded_input,url_input,text_input):
|
210 |
+
input = get_input(uploaded_input,url_input,text_input)
|
211 |
response = getattr(client, task)(input)
|
212 |
elif prompt_input:
|
213 |
if context_input is not None:
|
|
|
232 |
elif dict_hg_tasks_params[task]["output"] == "image":
|
233 |
response.save(os.path.join(cwd,"generated_image.png"))
|
234 |
image = Image.open(os.path.join(cwd,"generated_image.png"))
|
235 |
+
st.image(image)
|
|