Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,6 +20,25 @@ interpreter.auto_run = True
|
|
| 20 |
interpreter.llm.model = "gpt-4-turbo"
|
| 21 |
interpreter.custom_instructions = "First ask the user what they want to do. Based on the input, describe the next steps. If user agrees, proceed; if not, ask what they want next.If it is anything to display , always at the end open up the file."
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
def list_png_files(directory):
|
| 24 |
"""List .png files in a given directory, sorted by modification time."""
|
| 25 |
png_files = [os.path.join(directory, f) for f in os.listdir(directory) if f.endswith('.png')]
|
|
|
|
| 20 |
interpreter.llm.model = "gpt-4-turbo"
|
| 21 |
interpreter.custom_instructions = "First ask the user what they want to do. Based on the input, describe the next steps. If user agrees, proceed; if not, ask what they want next.If it is anything to display , always at the end open up the file."
|
| 22 |
|
| 23 |
+
def json_to_markdown(json_data):
|
| 24 |
+
full_message = []
|
| 25 |
+
images = []
|
| 26 |
+
# Regex to detect URLs; this is a simple version and might need to be adapted
|
| 27 |
+
url_pattern = r'(http[s]?://\S+|sandbox:/\S+)'
|
| 28 |
+
|
| 29 |
+
for item in json_data:
|
| 30 |
+
if item['role'] == 'assistant' and item['type'] == 'message':
|
| 31 |
+
content = item.get('content', " ")
|
| 32 |
+
# Find all URLs in the content
|
| 33 |
+
urls = re.findall(url_pattern, content)
|
| 34 |
+
# Append any detected URLs to the images list
|
| 35 |
+
images.extend(urls)
|
| 36 |
+
# Remove URLs from the content
|
| 37 |
+
content = re.sub(url_pattern, "", content).strip()
|
| 38 |
+
if content:
|
| 39 |
+
full_message.append(content)
|
| 40 |
+
return full_message, images
|
| 41 |
+
|
| 42 |
def list_png_files(directory):
|
| 43 |
"""List .png files in a given directory, sorted by modification time."""
|
| 44 |
png_files = [os.path.join(directory, f) for f in os.listdir(directory) if f.endswith('.png')]
|