Spaces:
Sleeping
Sleeping
Next cloud replaced
Browse files
app.py
CHANGED
|
@@ -79,54 +79,19 @@ def text_to_voice(sentence: str) -> bytes:
|
|
| 79 |
temp_file.write(voice.read())
|
| 80 |
temp_file.close()
|
| 81 |
|
| 82 |
-
|
| 83 |
-
nextcloud_url = os.environ.get("NEXTCLOUD_URL", "https://gbvolkoff.name:21512/")
|
| 84 |
-
nextcloud_username = os.environ.get("NEXTCLOUD_USERNAME", "gbvolkov@gmail.com")
|
| 85 |
-
nextcloud_password = os.environ.get("NEXTCLOUD_PASSWORD", "pihrow-becGu7-rizpip")
|
| 86 |
-
|
| 87 |
-
if not nextcloud_url or not nextcloud_username or not nextcloud_password:
|
| 88 |
-
os.remove(temp_file.name)
|
| 89 |
-
return "Nextcloud credentials not set"
|
| 90 |
-
|
| 91 |
-
# Upload file via WebDAV.
|
| 92 |
-
file_name = os.path.basename(temp_file.name)
|
| 93 |
-
upload_url = nextcloud_url.rstrip('/') + "/remote.php/webdav/" + file_name
|
| 94 |
try:
|
| 95 |
with open(temp_file.name, "rb") as f:
|
| 96 |
-
response = requests.
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
return f"Upload failed, error: {str(e)}"
|
| 103 |
-
|
| 104 |
-
# Create a public share for the file using Nextcloud's OCS API.
|
| 105 |
-
share_url = nextcloud_url.rstrip('/') + "/ocs/v1.php/apps/files_sharing/api/v1/shares"
|
| 106 |
-
headers = {"OCS-APIREQUEST": "true"}
|
| 107 |
-
data = {
|
| 108 |
-
"path": "/" + file_name, # assuming file is uploaded to the root directory
|
| 109 |
-
"shareType": 3, # public link
|
| 110 |
-
"permissions": 1 # read-only
|
| 111 |
-
}
|
| 112 |
-
try:
|
| 113 |
-
share_response = requests.post(share_url, headers=headers, data=data,
|
| 114 |
-
auth=(nextcloud_username, nextcloud_password))
|
| 115 |
-
if share_response.status_code != 200:
|
| 116 |
-
os.remove(temp_file.name)
|
| 117 |
-
return f"Share creation failed: HTTP {share_response.status_code} {share_response.text}"
|
| 118 |
-
import xml.etree.ElementTree as ET
|
| 119 |
-
root = ET.fromstring(share_response.text)
|
| 120 |
-
public_link = root.find(".//url").text
|
| 121 |
-
if not public_link:
|
| 122 |
-
public_link = f"Share creation failed: {share_response.text}"
|
| 123 |
-
|
| 124 |
except Exception as e:
|
| 125 |
-
|
| 126 |
-
return f"Share creation failed, error: {str(e)}"
|
| 127 |
|
| 128 |
os.remove(temp_file.name)
|
| 129 |
-
return
|
| 130 |
|
| 131 |
final_answer = FinalAnswerTool()
|
| 132 |
#model = HfApiModel(
|
|
|
|
| 79 |
temp_file.write(voice.read())
|
| 80 |
temp_file.close()
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
try:
|
| 83 |
with open(temp_file.name, "rb") as f:
|
| 84 |
+
response = requests.post(
|
| 85 |
+
"https://catbox.moe/user/api.php",
|
| 86 |
+
data={"reqtype": "fileupload"},
|
| 87 |
+
files={"fileToUpload": f}
|
| 88 |
+
)
|
| 89 |
+
public_url = response.text.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
except Exception as e:
|
| 91 |
+
public_url = f"Upload failed, error: {str(e)}"
|
|
|
|
| 92 |
|
| 93 |
os.remove(temp_file.name)
|
| 94 |
+
return public_url
|
| 95 |
|
| 96 |
final_answer = FinalAnswerTool()
|
| 97 |
#model = HfApiModel(
|