Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,7 +33,20 @@ def search_amazon(query: str, num: int = 10) -> str:
|
|
| 33 |
|
| 34 |
return links
|
| 35 |
|
|
|
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# Streamlit interface
|
| 38 |
st.title('Vision Shop - shopping via images')
|
| 39 |
url = st.text_input('Enter the url link to an image', 'Image URL')
|
|
@@ -66,8 +79,15 @@ if st.button('Shop'):
|
|
| 66 |
st.write(search_str)
|
| 67 |
|
| 68 |
amazon_output = search_amazon(search_str)
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
except Exception as e:
|
| 73 |
st.error(f'An error occurred: {e}')
|
|
|
|
| 33 |
|
| 34 |
return links
|
| 35 |
|
| 36 |
+
import re
|
| 37 |
|
| 38 |
+
def append_tag_to_amazon_url(input_string):
|
| 39 |
+
pattern = r'(https?://www\.amazon\.com[^)]*)'
|
| 40 |
+
|
| 41 |
+
def append_tag(match):
|
| 42 |
+
url = match.group(0)
|
| 43 |
+
if '?' in url:
|
| 44 |
+
return url + '&tag=dpang-20'
|
| 45 |
+
else:
|
| 46 |
+
return url + '?tag=dpang-20'
|
| 47 |
+
|
| 48 |
+
return re.sub(pattern, append_tag, input_string)
|
| 49 |
+
|
| 50 |
# Streamlit interface
|
| 51 |
st.title('Vision Shop - shopping via images')
|
| 52 |
url = st.text_input('Enter the url link to an image', 'Image URL')
|
|
|
|
| 79 |
st.write(search_str)
|
| 80 |
|
| 81 |
amazon_output = search_amazon(search_str)
|
| 82 |
+
|
| 83 |
+
processed_lines = [append_tag_to_amazon_url(line) for line in amazon_output.split('\n')]
|
| 84 |
+
output_str = '\n'.join(processed_lines)
|
| 85 |
+
|
| 86 |
+
print(output_str)
|
| 87 |
+
st.write(output_str)
|
| 88 |
+
|
| 89 |
+
#print(amazon_output)
|
| 90 |
+
#st.write(amazon_output)
|
| 91 |
|
| 92 |
except Exception as e:
|
| 93 |
st.error(f'An error occurred: {e}')
|