diff --git a/9. Image Processing Agent.ipynb b/9. Image Processing Agent.ipynb deleted file mode 100644 index 5e70903..0000000 --- a/9. Image Processing Agent.ipynb +++ /dev/null @@ -1,453 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 4, - "id": "1dfacc17-75d2-469d-ba91-4671f6b99940", - "metadata": {}, - "outputs": [], - "source": [ - "#Disable Proxy\n", - "\n", - "import os\n", - "\n", - "def clear_proxy_settings():\n", - " for var in [\"HTTP_PROXY\", \"HTTPS_PROXY\", \"ALL_PROXY\", \"http_proxy\", \"https_proxy\", \"all_proxy\"]:\n", - " if var in os.environ:\n", - " del os.environ[var]\n", - "\n", - "clear_proxy_settings()" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "6000a7d5-10c8-4e86-b737-7fd0c4d8cafe", - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'data': {'markdown': '## Description of Document\\n\\nThis document is a certificate of appreciation or recognition, featuring a formal layout with decorative elements. It is written in Persian and includes the following components:\\n\\n### Header\\n- **Title**: \"سومین اجلاس سراسری تجلیل از مدیران موفق ملی در انقلاب صنعتی چهارم\" (The Third National Conference for Honoring Successful National Managers in the Fourth Industrial Revolution)\\n- **Logos**: A series of logos from various organizations are displayed at the top, indicating the involvement or sponsorship of these entities.\\n- **Images**: There are two images of prominent figures in the top right corner, accompanied by a stylized Iranian flag.\\n\\n### Main Text\\n- **Recipient**: \"جناب آقای سید محمود خلیفه سلطانی\" (Mr. Seyed Mahmoud Khalifeh Soltani)\\n- **Position**: \"مدیرعامل محترم شرکت تکابو صنعت نامی (تایم پارک)\" (Respected CEO of Takabo Sanat Nami Company (Time Park))\\n- **Content**: The text praises the recipient\\'s management skills and contributions to the organization and the broader industry. It highlights the recipient\\'s role in strategic planning and support for organizational goals, emphasizing the importance of innovation and performance in the context of the Fourth Industrial Revolution.\\n\\n### Conclusion\\n- **Event Details**: The document mentions the event date as \"۱۲ مرداد ماه سال ۱۴۰۱\" (12th of Mordad, 1401 in the Iranian calendar).\\n- **Location**: The event took place at the \"مرکز همایش های بین المللی صدا و سیما\" (International Conference Center of IRIB).\\n\\n### Signatures\\n- The document is signed by several officials, each with their respective titles:\\n - \"دکتر رضا نصری\" (Dr. Reza Nasri)\\n - \"دکتر مژدهی پور\" (Dr. Mojdehi Pour)\\n - \"مهندس سید محمد کریمی\" (Engineer Seyed Mohammad Karimi)\\n - \"مهندس علی اکبر رضایی\" (Engineer Ali Akbar Rezaei)\\n\\n### Quote\\n- A motivational quote is included at the bottom: \"موفقیت روزافزون شما را از درگاه ایزد منان مسئلت می\\u200cنماییم\" (We wish you increasing success from the Almighty God).\\n\\n### Decorative Elements\\n- The document is bordered with ornate gold patterns, adding to its formal and prestigious appearance. ', 'chunks': [{'text': '## Description of Document\\n\\nThis document is a certificate of appreciation or recognition, featuring a formal layout with decorative elements. It is written in Persian and includes the following components:\\n\\n### Header\\n- **Title**: \"سومین اجلاس سراسری تجلیل از مدیران موفق ملی در انقلاب صنعتی چهارم\" (The Third National Conference for Honoring Successful National Managers in the Fourth Industrial Revolution)\\n- **Logos**: A series of logos from various organizations are displayed at the top, indicating the involvement or sponsorship of these entities.\\n- **Images**: There are two images of prominent figures in the top right corner, accompanied by a stylized Iranian flag.\\n\\n### Main Text\\n- **Recipient**: \"جناب آقای سید محمود خلیفه سلطانی\" (Mr. Seyed Mahmoud Khalifeh Soltani)\\n- **Position**: \"مدیرعامل محترم شرکت تکابو صنعت نامی (تایم پارک)\" (Respected CEO of Takabo Sanat Nami Company (Time Park))\\n- **Content**: The text praises the recipient\\'s management skills and contributions to the organization and the broader industry. It highlights the recipient\\'s role in strategic planning and support for organizational goals, emphasizing the importance of innovation and performance in the context of the Fourth Industrial Revolution.\\n\\n### Conclusion\\n- **Event Details**: The document mentions the event date as \"۱۲ مرداد ماه سال ۱۴۰۱\" (12th of Mordad, 1401 in the Iranian calendar).\\n- **Location**: The event took place at the \"مرکز همایش های بین المللی صدا و سیما\" (International Conference Center of IRIB).\\n\\n### Signatures\\n- The document is signed by several officials, each with their respective titles:\\n - \"دکتر رضا نصری\" (Dr. Reza Nasri)\\n - \"دکتر مژدهی پور\" (Dr. Mojdehi Pour)\\n - \"مهندس سید محمد کریمی\" (Engineer Seyed Mohammad Karimi)\\n - \"مهندس علی اکبر رضایی\" (Engineer Ali Akbar Rezaei)\\n\\n### Quote\\n- A motivational quote is included at the bottom: \"موفقیت روزافزون شما را از درگاه ایزد منان مسئلت می\\u200cنماییم\" (We wish you increasing success from the Almighty God).\\n\\n### Decorative Elements\\n- The document is bordered with ornate gold patterns, adding to its formal and prestigious appearance.', 'grounding': [{'box': {'l': 0.12374999999999999, 't': 0.0938125, 'r': 0.875, 'b': 0.9094875}, 'page': 0}], 'chunk_type': 'figure', 'chunk_id': '87793d22-eabd-42e3-93ac-001a763b7881'}]}}\n" - ] - } - ], - "source": [ - "import requests\n", - "\n", - "url = \"https://api.va.landing.ai/v1/tools/agentic-document-analysis\"\n", - "files = {\n", - " \"image\": open(\"/home/masih/Desktop/Temp/m.jpg\", \"rb\")\n", - "}\n", - "headers = {\n", - " \"Authorization\": \"Basic YWdmbjl0d200emV3cjVicHFzeXpuOmFBWGJCTGZRUFBsMzZVVWF3aXFVYVduY0hGVUdIQmhq\",\n", - "}\n", - "response = requests.post(url, files=files, headers=headers)\n", - "print(response.json())" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "9c628eb8-c8c2-433e-aa09-a3420d8d5d34", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{\n", - " \"data\": {\n", - " \"markdown\": \"## Description of Document\\n\\nThis document is a certificate of appreciation or recognition, featuring a formal layout with decorative elements. It is written in Persian and includes the following key components:\\n\\n### Header\\n- **Title**: سومین اجلاس سراسری تجلیل از مدیران موفق ملی در انقلاب صنعتی چهارم\\n - Translation: Third National Conference Honoring Successful National Managers in the Fourth Industrial Revolution\\n\\n### Visual Elements\\n- **Images**: \\n - Two portraits of prominent figures are located at the top right corner.\\n - A stylized emblem or logo is centered at the top.\\n - A ribbon with the colors of the Iranian flag is present near the top.\\n\\n### Main Text\\n- **Recipient**: جناب آقای سید محمود خلیفه سلطانی\\n - Translation: Mr. Seyed Mahmoud Khalifeh Soltani\\n- **Position**: مدیرعامل محترم شرکت تکابو صنعت نامی (تایم پارک)\\n - Translation: Honorable CEO of Takabo Sanat Nami Company (Time Park)\\n\\n- **Body**: The text praises the recipient's leadership and contributions to the organization, highlighting their role in strategic planning and support of organizational systems. It acknowledges the recipient's efforts in improving the company's performance and aligning with national economic policies.\\n\\n### Event Details\\n- **Event**: The document is related to the Third National Conference for Honoring Successful National Managers in the Fourth Industrial Revolution.\\n- **Date**: 12th of Mordad, 1401 (Persian calendar)\\n\\n### Signatures\\n- The document is signed by several officials, each with their respective titles:\\n - دکتر سید محمد حسینی\\n - دکتر مهدی عباسی\\n - دکتر مهدی کریمی تفرشی\\n - دکتر محمدرضا کرباسی\\n\\n### Closing Remark\\n- **Quote**: «موفقیت روزافزون شما را از درگاه ایزد منان مسئلت می‌نماییم»\\n - Translation: \\\"We wish you increasing success from the Almighty God.\\\"\\n\\n### Decorative Elements\\n- The document is bordered with ornate gold patterns, adding to its formal and prestigious appearance.\\n\\nThis certificate serves as a formal recognition of the recipient's achievements and contributions within the context of the Fourth Industrial Revolution in Iran. \",\n", - " \"chunks\": [\n", - " {\n", - " \"text\": \"## Description of Document\\n\\nThis document is a certificate of appreciation or recognition, featuring a formal layout with decorative elements. It is written in Persian and includes the following key components:\\n\\n### Header\\n- **Title**: سومین اجلاس سراسری تجلیل از مدیران موفق ملی در انقلاب صنعتی چهارم\\n - Translation: Third National Conference Honoring Successful National Managers in the Fourth Industrial Revolution\\n\\n### Visual Elements\\n- **Images**: \\n - Two portraits of prominent figures are located at the top right corner.\\n - A stylized emblem or logo is centered at the top.\\n - A ribbon with the colors of the Iranian flag is present near the top.\\n\\n### Main Text\\n- **Recipient**: جناب آقای سید محمود خلیفه سلطانی\\n - Translation: Mr. Seyed Mahmoud Khalifeh Soltani\\n- **Position**: مدیرعامل محترم شرکت تکابو صنعت نامی (تایم پارک)\\n - Translation: Honorable CEO of Takabo Sanat Nami Company (Time Park)\\n\\n- **Body**: The text praises the recipient's leadership and contributions to the organization, highlighting their role in strategic planning and support of organizational systems. It acknowledges the recipient's efforts in improving the company's performance and aligning with national economic policies.\\n\\n### Event Details\\n- **Event**: The document is related to the Third National Conference for Honoring Successful National Managers in the Fourth Industrial Revolution.\\n- **Date**: 12th of Mordad, 1401 (Persian calendar)\\n\\n### Signatures\\n- The document is signed by several officials, each with their respective titles:\\n - دکتر سید محمد حسینی\\n - دکتر مهدی عباسی\\n - دکتر مهدی کریمی تفرشی\\n - دکتر محمدرضا کرباسی\\n\\n### Closing Remark\\n- **Quote**: «موفقیت روزافزون شما را از درگاه ایزد منان مسئلت می‌نماییم»\\n - Translation: \\\"We wish you increasing success from the Almighty God.\\\"\\n\\n### Decorative Elements\\n- The document is bordered with ornate gold patterns, adding to its formal and prestigious appearance.\\n\\nThis certificate serves as a formal recognition of the recipient's achievements and contributions within the context of the Fourth Industrial Revolution in Iran.\",\n", - " \"grounding\": [\n", - " {\n", - " \"box\": {\n", - " \"l\": 0.12374999999999999,\n", - " \"t\": 0.0938125,\n", - " \"r\": 0.875,\n", - " \"b\": 0.9094875\n", - " },\n", - " \"page\": 0\n", - " }\n", - " ],\n", - " \"chunk_type\": \"figure\",\n", - " \"chunk_id\": \"c953c02f-d767-4307-8b1f-91cecc462482\"\n", - " }\n", - " ]\n", - " }\n", - "}\n" - ] - } - ], - "source": [ - "print(json.dumps(response_data, indent=2, ensure_ascii=False))" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "199f2372-acd7-4712-a716-c9d67cffdcab", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Extracted Persian Text:\n", - "سومین اجلاس سراسری تجلیل از مدیران موفق ملی در انقلاب صنعتی چهارم\n", - "جناب آقای سید محمود خلیفه سلطانی\n", - "مدیرعامل محترم شرکت تکابو صنعت نامی (تچیم پارک)\n", - "- دکتر سید محمد حسین سجادی نیری\n", - "- دکتر مهدی کریمیان\n", - "- دکتر مرتضی موسی خانی\n", - "- دکتر سید محمد حسین سجادی نیری\n", - "\n", - "Prompt for Gemma saved to 'gemma_prompt.md'\n", - "Original Persian text saved to 'persian_text.txt'\n" - ] - } - ], - "source": [ - "import requests\n", - "import json\n", - "\n", - "def extract_text_from_image(image_path):\n", - " url = \"https://api.va.landing.ai/v1/tools/agentic-document-analysis\"\n", - " files = {\"image\": open(image_path, \"rb\")}\n", - " headers = {\"Authorization\": \"Basic YWdmbjl0d200emV3cjVicHFzeXpuOmFBWGJCTGZRUFBsMzZVVWF3aXFVYVduY0hGVUdIQmhq\"}\n", - " response = requests.post(url, files=files, headers=headers)\n", - " return response.json()\n", - "\n", - "def extract_persian_text(response_data):\n", - " persian_texts = []\n", - " \n", - " if \"data\" in response_data and \"markdown\" in response_data[\"data\"]:\n", - " markdown = response_data[\"data\"][\"markdown\"]\n", - " lines = markdown.split(\"\\n\")\n", - " \n", - " for line in lines:\n", - " if \"**Title**:\" in line or \"**Recipient**:\" in line or \"**Position**:\" in line or \"**Quote**:\" in line:\n", - " # Extract Persian text after the colon\n", - " persian_part = line.split(\":\", 1)[1].strip()\n", - " persian_texts.append(persian_part)\n", - " elif line.startswith(\" - دکتر\"):\n", - " persian_texts.append(line.strip())\n", - " \n", - " return persian_texts\n", - "\n", - "def format_for_gemma(persian_texts):\n", - " prompt = \"# Certificate Text in Persian\\n\\n\"\n", - " for text in persian_texts:\n", - " prompt += f\"* {text}\\n\"\n", - " \n", - " prompt += \"\\n# Instructions\\n\"\n", - " prompt += \"Please provide the complete translation of this certificate text in Persian. \"\n", - " prompt += \"The certificate appears to be honoring someone for their achievements in business management. \"\n", - " prompt += \"Please reconstruct the full certificate text in proper Persian format.\"\n", - " \n", - " return prompt\n", - "\n", - "# Main execution\n", - "image_path = \"/home/masih/Desktop/Temp/m.jpg\"\n", - "response_data = extract_text_from_image(image_path)\n", - "\n", - "# Extract Persian text elements\n", - "persian_texts = extract_persian_text(response_data)\n", - "\n", - "# Create prompt for Gemma\n", - "gemma_prompt = format_for_gemma(persian_texts)\n", - "\n", - "# Save the Persian text and prompt\n", - "with open(\"persian_text.txt\", \"w\", encoding=\"utf-8\") as f:\n", - " f.write(\"\\n\".join(persian_texts))\n", - "\n", - "with open(\"gemma_prompt.md\", \"w\", encoding=\"utf-8\") as f:\n", - " f.write(gemma_prompt)\n", - "\n", - "# Print the extracted Persian text\n", - "print(\"Extracted Persian Text:\")\n", - "for text in persian_texts:\n", - " print(text)\n", - "\n", - "print(\"\\nPrompt for Gemma saved to 'gemma_prompt.md'\")\n", - "print(\"Original Persian text saved to 'persian_text.txt'\")" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "304bf08a-90e4-4c6b-b22d-2e3effac7c85", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Found 116 Persian text segments\n", - "\n", - "Sample of extracted Persian text:\n", - "- مسئله\n", - "- امکان\n", - "- مکانیزه\n", - "- کوتاه\n", - "- خودرو\n", - "\n", - "Prompt for Gemma saved to 'gemma_prompt.md'\n", - "Original Persian text saved to 'persian_text.txt'\n", - "Full API response saved to 'debug_response.json' for debugging\n" - ] - } - ], - "source": [ - "import requests\n", - "import json\n", - "import re\n", - "\n", - "def extract_text_from_image(image_path):\n", - " url = \"https://api.va.landing.ai/v1/tools/agentic-document-analysis\"\n", - " files = {\"image\": open(image_path, \"rb\")}\n", - " headers = {\"Authorization\": \"Basic YWdmbjl0d200emV3cjVicHFzeXpuOmFBWGJCTGZRUFBsMzZVVWF3aXFVYVduY0hGVUdIQmhq\"}\n", - " response = requests.post(url, files=files, headers=headers)\n", - " return response.json()\n", - "\n", - "def extract_persian_content(response_data):\n", - " # Persian Unicode range pattern\n", - " persian_pattern = re.compile(r'[\\u0600-\\u06FF\\uFB8A-\\uFBFF\\u0750-\\u077F\\u08A0-\\u08FF\\uFE70-\\uFEFF]+')\n", - " \n", - " all_text = \"\"\n", - " \n", - " # Check for markdown content\n", - " if \"data\" in response_data:\n", - " data = response_data[\"data\"]\n", - " \n", - " # Extract from markdown\n", - " if \"markdown\" in data and data[\"markdown\"]:\n", - " all_text += data[\"markdown\"] + \"\\n\"\n", - " \n", - " # Extract from chunks\n", - " if \"chunks\" in data and isinstance(data[\"chunks\"], list):\n", - " for chunk in data[\"chunks\"]:\n", - " if \"text\" in chunk:\n", - " all_text += chunk[\"text\"] + \"\\n\"\n", - " \n", - " # Extract from content\n", - " if \"content\" in data and data[\"content\"]:\n", - " all_text += data[\"content\"] + \"\\n\"\n", - " \n", - " # Find all Persian text\n", - " persian_matches = persian_pattern.findall(all_text)\n", - " persian_text = list(set(persian_matches)) # Remove duplicates\n", - " \n", - " # Filter out short matches (likely single characters or noise)\n", - " persian_text = [text for text in persian_text if len(text) > 2]\n", - " \n", - " return persian_text\n", - "\n", - "def format_for_gemma(persian_texts):\n", - " prompt = \"# Persian Text Extracted from Document\\n\\n\"\n", - " for i, text in enumerate(persian_texts, 1):\n", - " prompt += f\"{i}. {text}\\n\"\n", - " \n", - " prompt += \"\\n# Instructions\\n\"\n", - " prompt += \"Please analyze this Persian text and reconstruct the complete document content in proper Persian. \"\n", - " prompt += \"The text was extracted from an image and may be fragmented. \"\n", - " prompt += \"Create a coherent Persian document based on these fragments.\"\n", - " \n", - " return prompt\n", - "\n", - "def save_debug_info(response_data, filename=\"debug_response.json\"):\n", - " with open(filename, \"w\", encoding=\"utf-8\") as f:\n", - " json.dump(response_data, f, ensure_ascii=False, indent=2)\n", - "\n", - "# Main execution\n", - "image_path = \"/home/masih/Desktop/Temp/m2.png\"\n", - "response_data = extract_text_from_image(image_path)\n", - "\n", - "# Save debug info\n", - "save_debug_info(response_data)\n", - "\n", - "# Extract Persian text\n", - "persian_texts = extract_persian_content(response_data)\n", - "\n", - "# Create prompt for Gemma\n", - "gemma_prompt = format_for_gemma(persian_texts)\n", - "\n", - "# Save outputs\n", - "with open(\"persian_text.txt\", \"w\", encoding=\"utf-8\") as f:\n", - " f.write(\"\\n\".join(persian_texts))\n", - "\n", - "with open(\"gemma_prompt.md\", \"w\", encoding=\"utf-8\") as f:\n", - " f.write(gemma_prompt)\n", - "\n", - "# Print results\n", - "print(f\"Found {len(persian_texts)} Persian text segments\")\n", - "if persian_texts:\n", - " print(\"\\nSample of extracted Persian text:\")\n", - " for text in persian_texts[:5]:\n", - " print(f\"- {text}\")\n", - "else:\n", - " print(\"\\nNo Persian text found. Check debug_response.json for the API response.\")\n", - "\n", - "print(\"\\nPrompt for Gemma saved to 'gemma_prompt.md'\")\n", - "print(\"Original Persian text saved to 'persian_text.txt'\")\n", - "print(\"Full API response saved to 'debug_response.json' for debugging\")" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "id": "90f954d2-cb33-4c32-b3c2-4fff25d6b654", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Full extracted text saved to 'full_text.md'\n", - "Complete API response saved to 'full_response.json'\n" - ] - } - ], - "source": [ - "import requests\n", - "import json\n", - "import re\n", - "\n", - "def extract_text_from_image(image_path):\n", - " url = \"https://api.va.landing.ai/v1/tools/agentic-document-analysis\"\n", - " files = {\"image\": open(image_path, \"rb\")}\n", - " headers = {\"Authorization\": \"Basic YWdmbjl0d200emV3cjVicHFzeXpuOmFBWGJCTGZRUFBsMzZVVWF3aXFVYVduY0hGVUdIQmhq\"}\n", - " response = requests.post(url, files=files, headers=headers)\n", - " return response.json()\n", - "\n", - "def extract_full_text(response_data):\n", - " all_text = \"\"\n", - " \n", - " if \"data\" in response_data:\n", - " data = response_data[\"data\"]\n", - " \n", - " if \"markdown\" in data and data[\"markdown\"]:\n", - " all_text = data[\"markdown\"]\n", - " \n", - " return all_text\n", - "\n", - "def format_for_output(text):\n", - " # Format as readable markdown\n", - " output = \"# Extracted Document Content\\n\\n\"\n", - " output += text\n", - " \n", - " # Add instructions for Gemma\n", - " output += \"\\n\\n# Instructions for Gemma\\n\"\n", - " output += \"Please extract all Persian text from this document analysis and reconstruct the complete certificate in Persian language only.\"\n", - " \n", - " return output\n", - "\n", - "# Main execution\n", - "image_path = \"/home/masih/Desktop/Temp/m2.png\"\n", - "response_data = extract_text_from_image(image_path)\n", - "\n", - "# Save full API response for reference\n", - "with open(\"full_response.json\", \"w\", encoding=\"utf-8\") as f:\n", - " json.dump(response_data, f, ensure_ascii=False, indent=2)\n", - "\n", - "# Extract and format full text\n", - "full_text = extract_full_text(response_data)\n", - "formatted_output = format_for_output(full_text)\n", - "\n", - "# Save formatted output\n", - "with open(\"full_text.md\", \"w\", encoding=\"utf-8\") as f:\n", - " f.write(formatted_output)\n", - "\n", - "print(\"Full extracted text saved to 'full_text.md'\")\n", - "print(\"Complete API response saved to 'full_response.json'\")" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "8ca86af7-5cba-49fc-8761-a6f9c47e7ec2", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "بر اساس متن ارائه شده، سید محمود خلیفه سلطانی مدیرعامل شرکت تکابو صنعت نامی (تایم پارک) است. \n", - "\n" - ] - } - ], - "source": [ - "import requests\n", - "import json\n", - "from ollama import chat \n", - "\n", - "def image_to_gemma_response(image_path, query):\n", - " url = \"https://api.va.landing.ai/v1/tools/agentic-document-analysis\"\n", - " files = {\"image\": open(image_path, \"rb\")}\n", - " headers = {\"Authorization\": \"Basic YWdmbjl0d200emV3cjVicHFzeXpuOmFBWGJCTGZRUFBsMzZVVWF3aXFVYVduY0hGVUdIQmhq\"}\n", - " response = requests.post(url, files=files, headers=headers)\n", - " data = response.json()\n", - " extracted_text = \"\"\n", - " if \"data\" in data and \"markdown\" in data[\"data\"]:\n", - " extracted_text = data[\"data\"][\"markdown\"]\n", - " \n", - " prompt = f\"\"\"\n", - " # متن استخراج شده از تصویر:\n", - " {extracted_text}\n", - " \n", - " # سوال:\n", - " {query}\n", - " \n", - " لطفاً با استفاده از اطلاعات بالا، به سوال پاسخ دهید. پاسخ را به فارسی بنویسید.\n", - " \"\"\"\n", - "\n", - " messages = [{\"role\": \"user\", \"content\": prompt}]\n", - " response = chat(model=\"gemma2:9b\", messages=messages)\n", - " \n", - " return response['message']['content']\n", - "\n", - "image_path = \"/home/masih/Desktop/Temp/m.jpg\"\n", - "query = \"سید محمود خلیفه سلطانی کیست؟\"\n", - "\n", - "result = image_to_gemma_response(image_path, query)\n", - "print(result)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "147ebd1a-3a0c-42cd-8357-b30a5b634ac2", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python [conda env:base] *", - "language": "python", - "name": "conda-base-py" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.12.3" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -}