gbv commited on
Commit
f244277
·
1 Parent(s): 7da0b86

Mistral used

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +56 -20
  3. requirements.txt +3 -1
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ app_mistral.py
app.py CHANGED
@@ -7,6 +7,7 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
  from newsapi import NewsApiClient
 
10
 
11
  # Init
12
  NEWSAPI_API_KEY='cbcbfa28426a47b2bda9d246cefbf588'
@@ -77,34 +78,69 @@ def text_to_voice(sentence: str) -> bytes:
77
  temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
78
  temp_file.write(voice.read())
79
  temp_file.close()
 
 
 
 
 
 
 
 
 
80
 
81
- # Upload the file to catbox.moe using its API.
 
 
82
  try:
83
  with open(temp_file.name, "rb") as f:
84
- # The form field "fileToUpload" is expected by catbox.moe API.
85
- response = requests.post(
86
- "https://catbox.moe/user/api.php",
87
- data={"reqtype": "fileupload"},
88
- files={"fileToUpload": f}
89
- )
90
- public_url = response.text.strip()
91
  except Exception as e:
92
- public_url = f"Upload failed, error: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
 
 
 
 
94
  os.remove(temp_file.name)
95
-
96
- return public_url
97
 
98
  final_answer = FinalAnswerTool()
99
- model = HfApiModel(
100
- max_tokens=2096,
101
- temperature=0.5,
102
- #model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
103
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
104
- #model_id='mistralai/Mistral-Small-24B-Instruct-2501',
105
- #model_id="deepseek-ai/DeepSeek-V3",# it is possible that this model may be overloaded
106
- custom_role_conversions=None,
107
- )
 
 
 
108
 
109
 
110
  # Import tool from Hub
 
7
 
8
  from Gradio_UI import GradioUI
9
  from newsapi import NewsApiClient
10
+ from smolagents.models import OpenAIServerModel
11
 
12
  # Init
13
  NEWSAPI_API_KEY='cbcbfa28426a47b2bda9d246cefbf588'
 
78
  temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
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.put(upload_url, data=f, auth=(nextcloud_username, nextcloud_password))
97
+ if response.status_code not in (200, 201, 204):
98
+ os.remove(temp_file.name)
99
+ return f"Upload failed: HTTP {response.status_code} {response.text}"
 
 
 
100
  except Exception as e:
101
+ os.remove(temp_file.name)
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
+ os.remove(temp_file.name)
126
+ return f"Share creation failed, error: {str(e)}"
127
+
128
  os.remove(temp_file.name)
129
+ return public_link
 
130
 
131
  final_answer = FinalAnswerTool()
132
+ #model = HfApiModel(
133
+ # max_tokens=2096,
134
+ # temperature=0.5,
135
+ # #model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
136
+ # model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
137
+ # #model_id='mistralai/Mistral-Small-24B-Instruct-2501',
138
+ # #model_id="deepseek-ai/DeepSeek-V3",# it is possible that this model may be overloaded
139
+ # custom_role_conversions=None,
140
+ #)
141
+
142
+ mistral_api_key = os.environ.get("MISTRAL_API_KEY") # Set your API key in the environment
143
+ model = OpenAIServerModel(model_id='mistral-small-latest', api_base='https://api.mistral.ai/v1', api_key=mistral_api_key)
144
 
145
 
146
  # Import tool from Hub
requirements.txt CHANGED
@@ -5,6 +5,8 @@ duckduckgo_search
5
  pandas
6
  newsapi-python
7
  smolagents[gradio]
 
8
  soundfile
9
  num2words
10
- torch
 
 
5
  pandas
6
  newsapi-python
7
  smolagents[gradio]
8
+ smolagents[openai]
9
  soundfile
10
  num2words
11
+ torch
12
+ mistralai