File size: 5,498 Bytes
098b793
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a0cd5176",
   "metadata": {},
   "outputs": [],
   "source": [
    "# !wget https://huggingface.co/datasets/malaysia-ai/motomalaysia.com-multiturn/resolve/main/motomalaysia-data.jsonl.translated\n",
    "# !wget https://huggingface.co/datasets/malaysia-ai/motomalaysia.com-multiturn/resolve/main/motomalaysia-data.jsonl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b94471a6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a69c193d",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('motomalaysia-data.jsonl') as fopen:\n",
    "    for l in fopen:\n",
    "        l = json.loads(l)\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2907e6bd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n{\"image\": \"pic/0.jpg\", \"conversations\": [{\"role\": \"user\", \"content\": \"<image>Ini makanan apa?\"}, {\"role\": \"assistant\", \"content\": \"Ini ialah Kuih Siput.\"},\\n'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"\n",
    "{\"image\": \"pic/0.jpg\", \"conversations\": [{\"role\": \"user\", \"content\": \"<image>Ini makanan apa?\"}, {\"role\": \"assistant\", \"content\": \"Ini ialah Kuih Siput.\"},\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "41632e47",
   "metadata": {},
   "outputs": [],
   "source": [
    "chats = []\n",
    "with open('motomalaysia-data.jsonl.translated') as fopen:\n",
    "    for l in fopen:\n",
    "        l = json.loads(l)\n",
    "        overview = l['specs']['overview_translated']\n",
    "        overview = [s for s in overview if s]\n",
    "        overview = '\\n'.join(overview)\n",
    "        spec = '\\n'.join(l['specs']['specs'])\n",
    "        conversations = []\n",
    "        conversations.extend([\n",
    "            {\"role\": \"user\", \"content\": \"<image>Ini model apa?\"},\n",
    "            {\"role\": \"assistant\", \"content\": l['specs']['model_name']},\n",
    "        ])\n",
    "        if len(overview):\n",
    "            conversations.extend([\n",
    "                {\"role\": \"user\", \"content\": \"apa kelebihan moto tu?\"},\n",
    "                {\"role\": \"assistant\", \"content\": overview},\n",
    "            ])\n",
    "        conversations.extend([\n",
    "            {\"role\": \"user\", \"content\": \"apa spesifikasi moto tu?\"},\n",
    "            {\"role\": \"assistant\", \"content\": spec},\n",
    "        ])\n",
    "        chats.append({\n",
    "            'image': l['local_image'],\n",
    "            'image_url': l['img_url'],\n",
    "            'conversations': conversations\n",
    "        })"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "94cd0f04",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'image': 'pic/Yamaha NMAX (2016)_1.jpg',\n",
       " 'image_url': 'https://www.motomalaysia.com/wp-content/uploads/2017/10/yamaha-nmax-2.jpg',\n",
       " 'conversations': [{'role': 'user', 'content': '<image>Ini model apa?'},\n",
       "  {'role': 'assistant', 'content': 'Yamaha NMAX (2016)'},\n",
       "  {'role': 'user', 'content': 'apa spesifikasi moto tu?'},\n",
       "  {'role': 'assistant',\n",
       "   'content': 'Manufacturer: Yamaha\\nModel: 2016\\nGeneration: \\nYamaha NMAX (2016)\\n\\nType: Scooter\\nColour Available: \\n\\n Grey\\n Red\\n\\n\\nDimension: 1,955 x 740 x 1,115 mm\\nWheelbase: 1,350 mm\\nWeight: 136 kg\\nSeat Height: 765 mm\\nGround Clearance: 135 mm\\nMeter Display: \\n\\nDigital - Speedometer, Fuel Gauge\\n\\n\\nEngine: 4-Stroke, SOHC\\nDisplacement: 155 CC\\nNo Of Cylinders: 1-Cylinder\\nCompression Ratio: 10.5 : 1\\nBore x Stroke: 58mm x 58.7mm\\nMax Power: 11.1 kW @ 8,000 RPM\\nMax Torque: 14.4 Nm  @ 6,000 RPM\\nMax Speed: -\\nTransmission: Automatic, CVT\\nClutch: Dry, centrifugal, Shoe\\nIgnition System: Transistor Coil Ignition (TCI)\\nStarting System: Electric Starter\\nCooling System: Liquid Cooled\\nCarburetor: -\\nFuel System: Fuel Injection\\nFuel Capacity: 6.6 Liters\\nFuel Consumption: -\\nOil Capacity: 1.0 Liters\\nFeatures: -\\nType: Underbone\\nFront Suspension: Telescopic\\nRear Suspension: Unit Swing\\nFront Brake: Disc\\nRear Brake: Disc\\nFront Tire: 110/70-13\\nRear Tire: 130/70-13\\nFront Wheel: -\\nRear Wheel: -\\nUnder Seat Box: -'}]}"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chats[-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "75464efe",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('motomalaysia-chat.json', 'w') as fopen:\n",
    "    json.dump(chats, fopen)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "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.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}