image
imagewidth (px)
1.28k
4.48k
messages
listlengths
3
3
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "# Define here the models for your spider middleware\r\n#\r\n# See documentation in:\r\n# https://docs.scrapy.org/en/latest/topics/spider-middleware.html\r\n\r\nfrom scrapy import signals\r\n\r\n# useful for handling different item types with a single interface\r\nfrom itemadapter import is_item, ItemAdapter\r\n\r\n\r\nclass SlidesgoSpiderMiddleware:\r\n # Not all methods need to be defined. If a method is not defined,\r\n # scrapy acts as if the spider middleware does not modify the\r\n # passed objects.\r\n\r\n @classmethod\r\n def from_crawler(cls, crawler):\r\n # This method is used by Scrapy to create your spiders.\r\n s = cls()\r\n crawler.signals.connect(s.spider_opened, signal=signals.spider_opened)\r\n return s\r\n\r\n def process_spider_input(self, response, spider):\r\n # Called for each response that goes through the spider\r\n # middleware and into the spider.\r\n\r\n # Should return None or raise an exception.\r\n return None\r\n\r\n def process_spider_output(self, response, result, spider):\r\n # Called with the results returned from the Spider, after\r\n # it has processed the response.\r\n\r\n # Must return an iterable of Request, or item objects.\r\n for i in result:\r\n yield i\r\n\r\n def process_spider_exception(self, response, exception, spider):\r\n # Called when a spider or process_spider_input() method" } ]
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "from google_drive import GoogleDrive\r\n\r\n\r\nclient_secrets_file = 'drive.json'\r\ndrive = GoogleDrive(client_secret_file=client_secrets_file)\r\ndrive.authenticate()\r\n" } ]
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "import torch\r\nimport os\r\nfrom torch import nn\r\nfrom torchvision import transforms\r\nimport numpy as np\r\nimport os\r\nfrom PIL import Image\r\nimport torch\r\nimport os\r\nfrom torch import nn\r\nimport torch.nn.functional as F\r\nimport random\r\n\r\n\r\nclass MaizeNet(nn.Module):\r\n def __init__(self, K) -> None:\r\n super(MaizeNet, self).__init__()\r\n\r\n self.conv_layers = nn.Sequential(\r\n # convolution 1\r\n nn.Conv2d(in_channels=3, out_channels=32, kernel_size=3, padding=1),\r\n nn.ReLU(),\r\n nn.BatchNorm2d(32),\r\n nn.Conv2d(in_channels=32, out_channels=32, kernel_size=3, padding=1),\r\n nn.ReLU(),\r\n nn.BatchNorm2d(32),\r\n nn.MaxPool2d(2),\r\n # Convolution 2\r\n nn.Conv2d(in_channels=32, out_channels=64, kernel_size=3, padding=1),\r\n nn.ReLU(),\r\n nn.BatchNorm2d(64),\r\n nn.Conv2d(in_channels=64, out_channels=64, kernel_size=3, padding=1),\r\n nn.ReLU(),\r\n nn.BatchNorm2d(64),\r\n nn.MaxPool2d(2),\r\n # Convolution 3\r\n nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, padding=1),\r\n nn.ReLU(),\r\n nn.BatchNorm2d(128),\r\n nn.Conv2d(in_channels=128, out_channels=128, kernel_size=3, padding=1)," } ]
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "" } ]
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "from setuptools import find_packages, setup\r\nfrom pip._vendor import tomli\r\n\r\n# For consistent encoding\r\nfrom codecs import open\r\nfrom os import path\r\n\r\n# The directory containing this file\r\nHERE = path.abspath(path.dirname(__file__))\r\n\r\n# Get the long description from the README file\r\nwith open(path.join(HERE, 'README.md'), encoding='utf-8') as f:\r\n LONG_DESCRIPTION = f.read()\r\n\r\nwith open('pyproject.toml', 'r') as f:\r\n VERSION = tomli.load(f)['tool']['commitizen']['version']\r\n\r\nDESCRIPTION = 'A chatbot that enables the user interact with youtube over chat.'\r\n\r\nkey_words = [\r\n 'youtube', 'youtube-api', 'youtube comments', 'youtube videos', 'chat with youtube',\r\n 'youtube channels', 'youtube comment thread', 'create youtube playlist'\r\n]\r\n\r\ninstall_requires = [\r\n 'oryks-youtube',\r\n 'pydantic',\r\n 'pydantic-settings'\r\n]\r\n\r\nsetup(\r\n name='youtube-assistant',\r\n packages=find_packages(\r\n include=[\r\n 'assistant',\r\n ]\r\n ),\r\n version=VERSION,\r\n description=DESCRIPTION,\r\n long_description_content_type='text/markdown'," } ]
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "from collections import defaultdict\r\nfrom typing import Any\r\n\r\nfrom googleapiclient.http import MediaFileUpload\r\n\r\nfrom ...models import (\r\n BaseContentDetails,\r\n BaseSnippet,\r\n Language,\r\n LanguageSnippet,\r\n Region,\r\n RegionSnippet,\r\n Video,\r\n VideoAbuseReportReason,\r\n VideoAbuseReportReasonSnippet,\r\n VideoCategory,\r\n VideoCategorySnippet,\r\n)\r\nfrom ...schemas import (\r\n UploadVideo,\r\n VideoFilter,\r\n VideoOptionalParameters,\r\n VideoPart,\r\n VideoReportReasonSchema,\r\n YouTubeListResponse,\r\n YouTubeRatingResponse,\r\n YouTubeRequest,\r\n)\r\nfrom ..resource import YouTubeResource\r\n\r\n\r\nclass YouTubeVideo(YouTubeResource):\r\n def __init__(self, youtube_client: Any) -> None:\r\n super().__init__(youtube_client)\r\n\r\n def parse_snippet(self, snippet_data: dict[str, Any]) -> dict[str, Any]:\r\n base_snippet: BaseSnippet = self.parse_base_snippet(snippet_data)\r\n parsed_snippet: dict[str, Any] = base_snippet.model_dump()\r\n parsed_snippet['channel_id'] = snippet_data['channelId']\r\n parsed_snippet['channel_title'] = snippet_data['channelTitle']" } ]
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "#!/usr/bin/env python\r\nfrom __future__ import with_statement\r\n\r\nimport logging\r\nimport optparse\r\nimport os\r\nimport os.path\r\nimport re\r\nimport shutil\r\nimport subprocess\r\nimport sys\r\nimport itertools\r\n\r\n__version__ = '0.5.7'\r\n\r\n\r\nlogger = logging.getLogger()\r\n\r\n\r\nenv_bin_dir = 'bin'\r\nif sys.platform == 'win32':\r\n env_bin_dir = 'Scripts'\r\n\r\n\r\nclass UserError(Exception):\r\n pass\r\n\r\n\r\ndef _dirmatch(path, matchwith):\r\n \"\"\"Check if path is within matchwith's tree.\r\n\r\n >>> _dirmatch('/home/foo/bar', '/home/foo/bar')\r\n True\r\n >>> _dirmatch('/home/foo/bar/', '/home/foo/bar')\r\n True\r\n >>> _dirmatch('/home/foo/bar/etc', '/home/foo/bar')\r\n True\r\n >>> _dirmatch('/home/foo/bar2', '/home/foo/bar')\r\n False\r\n >>> _dirmatch('/home/foo/bar2/etc', '/home/foo/bar')" } ]
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "from argparse import ArgumentParser\r\n\r\nfrom dotenv import load_dotenv\r\n\r\nload_dotenv()\r\nimport os\r\nfrom os import path\r\n\r\nfrom .config import Config\r\nfrom .docstring_generator import generate_docstrings\r\nfrom .extensions import failed_modules_queue, modules_queue, processed_modules_queue\r\n\r\nparser: ArgumentParser = ArgumentParser()\r\nparser.add_argument(\"--path\", nargs=\"?\", default=\".\", type=str)\r\nparser.add_argument(\"--OPENAI_API_KEY\", nargs=\"?\", default=\"\", type=str)\r\nargs = parser.parse_args()\r\nsource_code_dir: str = args.path\r\n\r\nif not path.exists(source_code_dir):\r\n print(f\"The target directory '{source_code_dir}' doesn't exist\")\r\n raise SystemExit(1)\r\n\r\nif not args.OPENAI_API_KEY and not os.environ.get(\"OPENAI_API_KEY\", None):\r\n print(\"You have not provided the open ai api key.\")\r\n raise SystemExit(1)\r\n\r\nconfig: Config = Config(path=source_code_dir)\r\ngenerate_docstrings(\r\n config=config,\r\n modules_queue=modules_queue,\r\n processed_modules_queue=processed_modules_queue,\r\n failed_modules_queue=failed_modules_queue,\r\n)\r\n" } ]
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "from pydantic import BaseSettings\r\n\r\n\r\nclass Settings(BaseSettings):\r\n mongodb_uri: str\r\n mongodb_database: str\r\n\r\n\r\nsettings = Settings()\r\n" } ]
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "from .google_drive import GoogleDrive\r\n" } ]
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "import ast\r\nfrom ast import AST, FunctionDef, NodeTransformer\r\n\r\nfrom .config import Config\r\nfrom .helpers import generate_doc_string, make_docstring_node\r\nfrom .model_parsers import parse_function_docstr\r\n\r\n\r\nclass FunctionTransformer(NodeTransformer):\r\n def __init__(self, config: Config, function_src: str) -> None:\r\n super().__init__()\r\n self._config: Config = config\r\n self._function_src = function_src\r\n\r\n def visit_FunctionDef(self, node: FunctionDef) -> None:\r\n ast_tree: AST = ast.parse(self._function_src)\r\n function_node: AST = ast_tree.body[0]\r\n docstring: str = ast.get_docstring(node=node)\r\n if function_node.name == node.name:\r\n if not docstring:\r\n src_code: str = ast.unparse(node)\r\n func_docstr: str = generate_doc_string(\r\n src_code=src_code, config=self._config\r\n )\r\n doc_str: str = parse_function_docstr(func_docstr.strip())\r\n if doc_str:\r\n dcstr_node: AST = make_docstring_node(doc_str)\r\n node.body.insert(0, dcstr_node)\r\n elif self._config.overwrite_function_docstring:\r\n src_code: str = ast.unparse(node)\r\n func_docstr: str = generate_doc_string(\r\n src_code=src_code, config=self._config\r\n )\r\n doc_str: str = parse_function_docstr(func_docstr.strip())\r\n if doc_str:\r\n dcstr_node: AST = make_docstring_node(doc_str)\r\n node.body[0] = dcstr_node\r\n return node\r\n" } ]
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "from setuptools import find_packages, setup\r\nfrom pip._vendor import tomli\r\n\r\n# For consistent encoding\r\nfrom codecs import open\r\nfrom os import path\r\n\r\n# The directory containing this file\r\nHERE = path.abspath(path.dirname(__file__))\r\n\r\n# Get the long description from the README file\r\nwith open(path.join(HERE, 'README.md'), encoding='utf-8') as f:\r\n LONG_DESCRIPTION = f.read()\r\n\r\nwith open('pyproject.toml', 'r') as f:\r\n VERSION = tomli.load(f)['tool']['commitizen']['version']\r\n\r\nDESCRIPTION = 'A chatbot that enables the user interact with youtube over chat.'\r\n\r\nkey_words = [\r\n 'youtube', 'youtube-api', 'youtube comments', 'youtube videos', 'chat with youtube',\r\n 'youtube channels', 'youtube comment thread', 'create youtube playlist'\r\n]\r\n\r\ninstall_requires = [\r\n 'oryks-youtube',\r\n 'pydantic',\r\n 'pydantic-settings'\r\n]\r\n\r\nsetup(\r\n name='youtube-assistant',\r\n packages=find_packages(\r\n include=[\r\n 'assistant',\r\n ]\r\n ),\r\n version=VERSION,\r\n description=DESCRIPTION,\r\n long_description_content_type='text/markdown'," } ]
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "\"\"\"This module declares the app configuration.\r\n\r\nThe classes include:\r\n\r\nBaseConfig:\r\n Has all the configurations shared by all the environments.\r\n\r\n\"\"\"\r\nimport os\r\n\r\nfrom dotenv import load_dotenv\r\n\r\nload_dotenv()\r\n\r\n\r\nclass BaseConfig:\r\n \"\"\"Base configuration.\"\"\"\r\n\r\n DEBUG = True\r\n TESTING = False\r\n SECRET_KEY = os.environ.get(\r\n \"SECRET_KEY\", \"df0331cefc6c2b9a5d0208a726a5d1c0fd37324feba25506\"\r\n )\r\n\r\n\r\nclass DevelopmentConfig(BaseConfig):\r\n \"\"\"Development confuguration.\"\"\"\r\n\r\n DEBUG = True\r\n TESTING = False\r\n SECRET_KEY = os.environ.get(\r\n \"SECRET_KEY\", \"df0331cefc6c2b9a5d0208a726a5d1c0fd37324feba25506\"\r\n )\r\n\r\n\r\nclass TestingConfig(BaseConfig):\r\n \"\"\"Testing configuration.\"\"\"\r\n\r\n TESTING = True\r\n SECRET_KEY = os.environ.get(\"SECRET_KEY\", \"secret-key\")" } ]
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "from ..auth.models.user import User\r\nfrom ..post.models.post_model import Post\r\nfrom ..post.models.like_model import Like\r\nfrom ..post.models.comment_model import Comment\r\nfrom faker import Faker\r\nfrom datetime import datetime, timedelta\r\nfake = Faker()\r\nimport random\r\nfrom ..extensions.extensions import db, bcrypt\r\n\r\ndef generate_users(count: int = 10) -> list[User]:\r\n \"\"\"Generate ten random users.\"\"\"\r\n profile_pictures = (f'profile-{i}.jpg' for i in range(count))\r\n names = (fake.name() for _ in range(count))\r\n emails = (fake.email() for i in range(count))\r\n password = hashed_password = bcrypt.generate_password_hash(\"password\").decode(\r\n \"utf-8\"\r\n )\r\n return [\r\n User(\r\n username=name,\r\n email=email,\r\n image_file=profile_pic,\r\n password=password,\r\n account_activated=True\r\n ) \r\n for profile_pic, name, email in zip(profile_pictures, names, emails)\r\n ]\r\n\r\ndef generate_posts(authors: list[User], count: int = 100) -> list[Post]:\r\n \"\"\"Generate posts.\"\"\"\r\n cities = [fake.city() for _ in range(10)]\r\n posts_text = [fake.text() for _ in range(count)]\r\n post_images = [f'feed-{i}.jpg' for i in range(8)]\r\n dates_published = (datetime.now() + timedelta(minutes=random.randint(1,60)) for _ in range(count))\r\n return [\r\n Post(\r\n author=random.choice(authors),\r\n location=random.choice(cities),\r\n text=text," } ]
[ { "role": "SYSTEM", "content": "You are a helpful assistant that knows how to extract python code from images." }, { "role": "USER", "content": "Extract python code from the given image." }, { "role": "ASSISTANT", "content": "from sqlalchemy.orm import Session\r\nfrom .models.channel import Channel\r\nfrom sqlalchemy.exc import IntegrityError\r\n\r\ndef add_channel(session: Session, channel: Channel):\r\n with session() as db:\r\n try:\r\n db.add(channel)\r\n db.commit()\r\n db.refresh(channel)\r\n except IntegrityError:\r\n return None\r\n else:\r\n return channel" } ]