Add files via upload

This commit is contained in:
FatihMakes authored and GitHub committed 2026-05-02 11:51:56 +03:00
1 parent ff7a982d82
commit c36079104e
17 files changed
+2854 -1210

No files matched your search

+76 -15
View File
@@ -14,6 +14,7 @@ from memory.memory_manager import (
load_memory, update_memory, format_memory_for_prompt,
)
from actions.file_processor import file_processor
from actions.flight_finder import flight_finder
from actions.open_app import open_app
from actions.weather_report import weather_action
@@ -47,7 +48,6 @@ SEND_SAMPLE_RATE = 16000
RECEIVE_SAMPLE_RATE = 24000
CHUNK_SIZE = 1024
def _get_api_key() -> str:
with open(API_CONFIG_PATH, "r", encoding="utf-8") as f:
return json.load(f)["gemini_api_key"]
@@ -63,18 +63,13 @@ def _load_system_prompt() -> str:
"Never simulate or guess results — always call the appropriate tool."
)
# ── Transkripsiyon temizleyici ─────────────────────────────────────────────────
_CTRL_RE = re.compile(r"<ctrl\d+>", re.IGNORECASE)
def _clean_transcript(text: str) -> str:
"""Gemini'nin ürettiği <ctrlXX> artefaktlarını ve kontrol karakterlerini temizler."""
def _clean_transcript(text: str) -> str:
text = _CTRL_RE.sub("", text)
text = re.sub(r"[\x00-\x08\x0b-\x1f]", "", text)
return text.strip()
# ── Tool declarations ──────────────────────────────────────────────────────────
TOOL_DECLARATIONS = [
{
"name": "open_app",
@@ -387,6 +382,72 @@ TOOL_DECLARATIONS = [
"properties": {},
}
},
{
"name": "file_processor",
"description": (
"Processes any file that the user has uploaded or dropped onto the interface. "
"Use this when the user refers to an uploaded file and wants an action on it. "
"Supports: images (describe/ocr/resize/compress/convert), "
"PDFs (summarize/extract_text/to_word), "
"Word docs & text files (summarize/fix/reformat/translate), "
"CSV/Excel (analyze/stats/filter/sort/convert), "
"JSON/XML (validate/format/analyze), "
"code files (explain/review/fix/optimize/run/document/test), "
"audio (transcribe/trim/convert/info), "
"video (trim/extract_audio/extract_frame/compress/transcribe/info), "
"archives (list/extract), "
"presentations (summarize/extract_text). "
"ALWAYS call this tool when a file has been uploaded and the user gives a command about it. "
"If the user's command is ambiguous, pick the most logical action for that file type."
),
"parameters": {
"type": "OBJECT",
"properties": {
"file_path": {
"type": "STRING",
"description": "Full path to the uploaded file. Leave empty to use the currently uploaded file."
},
"action": {
"type": "STRING",
"description": (
"What to do with the file. Examples by type:\n"
"image: describe | ocr | resize | compress | convert | info\n"
"pdf: summarize | extract_text | to_word | info\n"
"docx/txt: summarize | fix | reformat | translate_hint | word_count | to_bullet\n"
"csv/excel: analyze | stats | filter | sort | convert | info\n"
"json: validate | format | analyze | to_csv\n"
"code: explain | review | fix | optimize | run | document | test\n"
"audio: transcribe | trim | convert | info\n"
"video: trim | extract_audio | extract_frame | compress | transcribe | info | convert\n"
"archive: list | extract\n"
"pptx: summarize | extract_text | analyze"
)
},
"instruction": {
"type": "STRING",
"description": "Free-form instruction if action doesn't cover it. E.g. 'translate this to Turkish', 'find all email addresses'"
},
"format": {
"type": "STRING",
"description": "Target format for conversion. E.g. 'mp3', 'pdf', 'csv', 'png'"
},
"width": {"type": "INTEGER", "description": "Target width for image resize"},
"height": {"type": "INTEGER", "description": "Target height for image resize"},
"scale": {"type": "NUMBER", "description": "Scale factor for image resize (e.g. 0.5)"},
"quality": {"type": "INTEGER", "description": "Quality 1-100 for image/video compress"},
"start": {"type": "STRING", "description": "Start time for trim: seconds or HH:MM:SS"},
"end": {"type": "STRING", "description": "End time for trim: seconds or HH:MM:SS"},
"timestamp": {"type": "STRING", "description": "Timestamp for video frame extraction HH:MM:SS"},
"column": {"type": "STRING", "description": "Column name for CSV filter/sort"},
"value": {"type": "STRING", "description": "Filter value for CSV filter"},
"condition": {"type": "STRING", "description": "Filter condition: equals|contains|gt|lt"},
"ascending": {"type": "BOOLEAN", "description": "Sort order for CSV sort (default: true)"},
"save": {"type": "BOOLEAN", "description": "Save result to file (default: true)"},
"destination": {"type": "STRING", "description": "Output folder for archive extract"},
},
"required": []
}
},
{
"name": "save_memory",
"description": (
@@ -419,7 +480,6 @@ TOOL_DECLARATIONS = [
},
]
class JarvisLive:
def __init__(self, ui: JarvisUI):
@@ -511,7 +571,6 @@ class JarvisLive:
print(f"[JARVIS] 🔧 {name} {args}")
self.ui.set_state("THINKING")
# ── save_memory: sessiz ve hızlı ──────────────────────────────────────
if name == "save_memory":
category = args.get("category", "notes")
key = args.get("key", "")
@@ -593,6 +652,14 @@ class JarvisLive:
elif name == "web_search":
r = await loop.run_in_executor(None, lambda: web_search_action(parameters=args, player=self.ui))
result = r or "Done."
elif name == "file_processor":
if not args.get("file_path") and self.ui.current_file:
args["file_path"] = self.ui.current_file
r = await loop.run_in_executor(
None,
lambda: file_processor(parameters=args, player=self.ui, speak=self.speak)
)
result = r or "Done."
elif name == "computer_control":
r = await loop.run_in_executor(None, lambda: computer_control(parameters=args, player=self.ui))
@@ -715,7 +782,6 @@ class JarvisLive:
await self.session.send_tool_response(
function_responses=fn_responses
)
except Exception as e:
print(f"[JARVIS] ❌ Recv: {e}")
traceback.print_exc()
@@ -748,10 +814,8 @@ class JarvisLive:
self.set_speaking(False)
self._turn_done_event.clear()
continue
self.set_speaking(True)
await asyncio.to_thread(stream.write, chunk)
except Exception as e:
print(f"[JARVIS] ❌ Play: {e}")
raise
@@ -794,13 +858,11 @@ class JarvisLive:
except Exception as e:
print(f"[JARVIS] ⚠️ {e}")
traceback.print_exc()
self.set_speaking(False)
self.ui.set_state("THINKING")
print("[JARVIS] 🔄 Reconnecting in 3s...")
await asyncio.sleep(3)
def main():
ui = JarvisUI("face.png")
@@ -815,6 +877,5 @@ def main():
threading.Thread(target=runner, daemon=True).start()
ui.root.mainloop()
if __name__ == "__main__":
main()