Circularmachines commited on
Commit
79f15ad
1 Parent(s): 31a3584

Upload folder using huggingface_hub

Browse files
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ .venv
2
+ captured_images
3
+ camera-shutter.wav
4
+ gemini.ipynb
5
+ photos.py
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Johans Verktyg
3
- emoji: 🐠
4
- colorFrom: blue
5
- colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 4.29.0
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Johans_Verktyg
3
+ app_file: app.py
 
 
4
  sdk: gradio
5
  sdk_version: 4.29.0
 
 
6
  ---
 
 
app.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ tool_str=""
3
+
4
+ import json
5
+
6
+ # Specify the file path to your JSON file
7
+ file_path = 'data.json'
8
+
9
+ # Reading JSON data
10
+ with open(file_path, 'r') as file:
11
+ data = json.load(file)
12
+
13
+
14
+
15
+ for t in data:
16
+
17
+ tool_str+=t['new_name']+" : "
18
+ tool_str+=t['text']+"\n"
19
+
20
+ system_prompt=f"""You help out with tools! From the users request, pick the most usable tool from the list.
21
+
22
+ {tool_str}"""
23
+
24
+ from openai import OpenAI
25
+
26
+
27
+ import os
28
+
29
+ client = OpenAI(api_key=os.environ.get("OPEN_AI_KEY"))
30
+
31
+ system_prompt=f"""You help out with tools! From the users request, pick the most usable tool from the list.
32
+
33
+ {tool_str}"""
34
+
35
+
36
+ def run_conversation(text):
37
+ # Step 1: send the conversation and available functions to the model
38
+ messages = [
39
+ {
40
+ "role": "system",
41
+ "content": system_prompt
42
+ },
43
+ {
44
+ "role": "user",
45
+ "content": text
46
+ }
47
+
48
+ ]
49
+ tools = [
50
+ {
51
+ "type": "function",
52
+ "function": {
53
+ "name": "output_file_path",
54
+ "description": "outputs the best suited file path",
55
+ "parameters": {
56
+ "type": "object",
57
+ "properties": {
58
+ "file_path": {
59
+ "type": "string",
60
+ "description": "File path starting with captured_images/...",
61
+ },
62
+
63
+ },
64
+ "required": ["file_path"],
65
+ },
66
+ },
67
+ }
68
+ ]
69
+ response = client.chat.completions.create(
70
+ model="gpt-3.5-turbo-0125",
71
+ messages=messages,
72
+ tools=tools,
73
+ tool_choice="required",
74
+ )
75
+ response_message = response.choices[0].message
76
+
77
+ image_path=json.loads(response.choices[0].message.tool_calls[0].function.arguments)['file_path']
78
+
79
+ messages.append({
80
+ "role": "system",
81
+ "content": f"Chosen file_path: {image_path}\n Now respond with a friendly answer with your reasoning in the same language as the incoming message"
82
+ })
83
+
84
+ response2 = client.chat.completions.create(
85
+ model="gpt-3.5-turbo-0125",
86
+ messages=messages
87
+ )
88
+
89
+ return image_path, response2.choices[0].message.content
90
+
91
+ import gradio as gr
92
+ from PIL import Image
93
+ import re
94
+
95
+
96
+
97
+ def show_image(text):
98
+
99
+ try:
100
+
101
+ image_path, response=run_conversation(text)
102
+ img = Image.open(image_path)
103
+ return img, response
104
+ except Exception as e:
105
+ return f"Error: {str(e)}" # Return error message if path is invalid or file is not found
106
+
107
+ def main():
108
+ # Define the interface
109
+ interface = gr.Interface(
110
+ fn=show_image,
111
+ inputs="text",
112
+ outputs=["image", "text"],
113
+ title="Johans verktyg!",
114
+ description="Be om ett verktyg så plockar Johan fram det!"
115
+ )
116
+ # Launch the interface
117
+ interface.launch(share=True)
118
+
119
+ if __name__ == "__main__":
120
+ main()
data.json ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "file": "captured_images/2024-05-06/image_18-39-46.png",
4
+ "text": "The man is holding a socket wrench, a tool used for tightening or loosening nuts and bolts, featuring a ratcheting mechanism that allows the wrench to turn the fastener in one direction while moving freely in the opposite direction.",
5
+ "new_name": "new_names/socket_wrench.png"
6
+ },
7
+ {
8
+ "file": "captured_images/2024-05-06/image_18-39-53.png",
9
+ "text": "The tool being held is a claw hammer, characterized by a metal head with a flat hammering surface on one side and a curved claw for pulling nails on the other; it is commonly used for driving nails into, or pulling them from, another object.",
10
+ "new_name": "new_names/claw_hammer.png"
11
+ },
12
+ {
13
+ "file": "captured_images/2024-05-06/image_18-40-00.png",
14
+ "text": "The tool is a folding ruler, segmented and made of wood or plastic, often used in carpentry and construction to measure distances or draw straight lines over larger spans.",
15
+ "new_name": "new_names/folding_ruler.png"
16
+ },
17
+ {
18
+ "file": "captured_images/2024-05-06/image_18-40-07.png",
19
+ "text": "The tool being held is a coping saw, characterized by its thin blade tensioned in a C-shaped frame, used primarily for cutting intricate external shapes and interior cutouts in woodworking or carpentry.",
20
+ "new_name": "new_names/coping_saw.png"
21
+ },
22
+ {
23
+ "file": "captured_images/2024-05-06/image_18-40-14.png",
24
+ "text": "The man is holding a flathead screwdriver, which is a tool used for driving screws with a linear notch on their heads; it has a yellow and black handle and a metal shaft that specifies \"0.8x4.0x75mm,\" indicating the tip and shaft dimensions.",
25
+ "new_name": "new_names/screwdriver.png"
26
+ },
27
+ {
28
+ "file": "captured_images/2024-05-06/image_18-40-29.png",
29
+ "text": "The tool being held is a manual nut driver with a yellow and black handle, designed for use in tightening or loosening nuts, particularly in areas where a standard wrench may not fit effectively.",
30
+ "new_name": "new_names/nut_driver.png"
31
+ },
32
+ {
33
+ "file": "captured_images/2024-05-06/image_18-40-36.png",
34
+ "text": "The tool being held is a \"slip joint plier,\" typically used for gripping and bending hardware or wire, featuring adjustable jaw positions for versatility.",
35
+ "new_name": "new_names/slip_joint_plier.png"
36
+ },
37
+ {
38
+ "file": "captured_images/2024-05-06/image_18-40-43.png",
39
+ "text": "The tool is a digital caliper, used for measuring distances with high precision, often found in fields involving machining, carpentry, engineering, and metalworking.",
40
+ "new_name": "new_names/digital_caliper.png"
41
+ },
42
+ {
43
+ "file": "captured_images/2024-05-06/image_18-40-50.png",
44
+ "text": "The tool is a red-capped permanent marker, typically used for writing on various surfaces where the ink is required to be waterproof and smudge-proof.",
45
+ "new_name": "new_names/red_capped_permanent_marker.png"
46
+ },
47
+ {
48
+ "file": "captured_images/2024-05-06/image_18-40-57.png",
49
+ "text": "The tool is a yellow and black Torx T5 screwdriver, used for precision tasks such as repairing electronics or assembling small machinery.",
50
+ "new_name": "new_names/yellow_black_torx_T5_screwdriver.png"
51
+ },
52
+ {
53
+ "file": "captured_images/2024-05-06/image_18-41-18.png",
54
+ "text": "The tool the man is holding appears to be a flexible drill bit extension, which is used to extend the reach of a drill bit, allowing it to bend around corners and access difficult-to-reach areas.",
55
+ "new_name": "new_names/flexible_drill_bit_extension.png"
56
+ },
57
+ {
58
+ "file": "captured_images/2024-05-06/image_18-41-32.png",
59
+ "text": "The tool pictured is a C-clamp, which is used to hold parts together by applying pressure, commonly utilized in carpentry and metalworking for securing workpieces.",
60
+ "new_name": "new_names/c_clamp.png"
61
+ },
62
+ {
63
+ "file": "captured_images/2024-05-06/image_18-41-46.png",
64
+ "text": "The tool in the image is a black power cord with a three-pronged plug, typically used for providing electrical power to appliances and electronic devices.",
65
+ "new_name": "new_names/power_cord.png"
66
+ },
67
+ {
68
+ "file": "captured_images/2024-05-06/image_18-41-54.png",
69
+ "text": "The tool in the image is a vernier caliper, which is used for taking precise measurements of internal and external dimensions as well as depths.",
70
+ "new_name": "new_names/vernier_caliper.png"
71
+ },
72
+ {
73
+ "file": "captured_images/2024-05-06/image_18-42-01.png",
74
+ "text": "The tool being held is a yellow and black screwdriver, likely a precision or electronics screwdriver, used for small repairs or tasks requiring attention to detail, such as tightening screws in electronic devices.",
75
+ "new_name": "new_names/yellow_black_screwdriver.png"
76
+ },
77
+ {
78
+ "file": "captured_images/2024-05-06/image_18-42-15.png",
79
+ "text": "The tool being held is a small screwdriver with a yellow and black handle and a Phillips head, used for tightening or loosening screws.",
80
+ "new_name": "new_names/small_screwdriver.png"
81
+ },
82
+ {
83
+ "file": "captured_images/2024-05-06/image_18-42-29.png",
84
+ "text": "The man is holding a half-round metal file with a red handle, which is commonly used for smoothing and shaping wood or metal.",
85
+ "new_name": "new_names/metal_file_red_handle.png"
86
+ },
87
+ {
88
+ "file": "captured_images/2024-05-06/image_18-42-36.png",
89
+ "text": "The man is holding a heavy-duty staple gun, which is used for driving staples into wood, plastic, or metal for various construction or upholstery projects.",
90
+ "new_name": "new_names/staple_gun.png"
91
+ },
92
+ {
93
+ "file": "captured_images/2024-05-06/image_18-42-43.png",
94
+ "text": "The man is holding a putty knife, a tool with a flat, flexible blade used for applying and smoothing putty or filler, and for scraping surfaces.",
95
+ "new_name": "new_names/putty_knife.png"
96
+ },
97
+ {
98
+ "file": "captured_images/2024-05-06/image_18-42-57.png",
99
+ "text": "The tool being held is a torque wrench, specifically marked with \"T25x100mm,\" which indicates it is a Torx T25 driver used for applying a precise amount of torque to a screw or bolt.",
100
+ "new_name": "new_names/torque_wrench.png"
101
+ },
102
+ {
103
+ "file": "captured_images/2024-05-06/image_18-43-04.png",
104
+ "text": "The tool in the image appears to be a well-used wood chisel, characterized by its straight cutting edge and a sturdy handle, typically employed for carving or cutting hard materials such as wood or stone.",
105
+ "new_name": "new_names/wood_chisel.png"
106
+ },
107
+ {
108
+ "file": "captured_images/2024-05-06/image_18-43-11.png",
109
+ "text": "The man is holding a portable spanner wrench, which is a tool used for turning nuts, bolts, or other hard-to-grip items by providing leverage with its adjustable U-shaped jaw end.",
110
+ "new_name": "new_names/spanner_wrench.png"
111
+ },
112
+ {
113
+ "file": "captured_images/2024-05-06/image_18-43-19.png",
114
+ "text": "The tool being held is a crowbar, specifically designed with a curved, flattened end and a forked end, used for prying, lifting, and pulling nails.",
115
+ "new_name": "new_names/crowbar.png"
116
+ },
117
+ {
118
+ "file": "captured_images/2024-05-06/image_18-43-26.png",
119
+ "text": "The man is holding a black sliding T-bevel with red handles, which is a tool used for transferring angles from one piece of work to another or for setting the angle of a saw blade.",
120
+ "new_name": "new_names/black_sliding_T-bevel_with_red_handles.png"
121
+ },
122
+ {
123
+ "file": "captured_images/2024-05-06/image_18-43-33.png",
124
+ "text": "The tool in the image is a flat paintbrush with a yellow handle and black bristles, typically used for painting broad, even strokes on surfaces such as walls or canvases.",
125
+ "new_name": "new_names/flat_paintbrush_yellow_handle_black_bristles.png"
126
+ },
127
+ {
128
+ "file": "captured_images/2024-05-06/image_18-43-40.png",
129
+ "text": "The tool is a pair of orange-handled scissors with stainless steel blades, commonly used for cutting paper, fabric, or other materials.",
130
+ "new_name": "new_names/scissors.png"
131
+ },
132
+ {
133
+ "file": "captured_images/2024-05-06/image_18-43-47.png",
134
+ "text": "The tool is a pair of slip joint pliers with red handles, used for gripping, bending, and cutting wire and other materials.",
135
+ "new_name": "new_names/slip_joint_pliers.png"
136
+ },
137
+ {
138
+ "file": "captured_images/2024-05-06/image_18-43-54.png",
139
+ "text": "The tool is a large adjustable wrench, used for turning or holding nuts and bolts of varying sizes.",
140
+ "new_name": "new_names/adjustable_wrench.png"
141
+ },
142
+ {
143
+ "file": "captured_images/2024-05-06/image_18-44-01.png",
144
+ "text": "The man is holding a roll of white adhesive tape, commonly used for packaging, sealing boxes, and general fastening or repair tasks.",
145
+ "new_name": "new_names/white_adhesive_tape.png"
146
+ },
147
+ {
148
+ "file": "captured_images/2024-05-06/image_18-44-15.png",
149
+ "text": "The tool is a multi-size bike hex wrench set, commonly used for adjusting bolts on bicycles, consisting of several hexagonal Allen keys of different sizes that fold into a single compact handle.",
150
+ "new_name": "new_names/bike_hex_wrench_set.png"
151
+ },
152
+ {
153
+ "file": "captured_images/2024-05-06/image_18-44-23.png",
154
+ "text": "The tool is a pair of slip joint pliers, featuring a slotted joint design allowing the jaws to be adjusted to grip objects of varying sizes, commonly used for gripping, bending, and cutting wire.",
155
+ "new_name": "new_names/slip_joint_pliers.png"
156
+ },
157
+ {
158
+ "file": "captured_images/2024-05-06/image_18-44-30.png",
159
+ "text": "The tool is a locking pliers with a curved jaw, commonly used for gripping and turning nuts or bolts or for holding objects securely in place.",
160
+ "new_name": "new_names/locking_pliers.png"
161
+ },
162
+ {
163
+ "file": "captured_images/2024-05-06/image_18-44-44.png",
164
+ "text": "The tool is a voltage tester screwdriver, which features a clear handle with a neon bulb inside for detecting electrical current presence in wires, outlets, or circuitry.",
165
+ "new_name": "new_names/voltage_tester_screwdriver.png"
166
+ },
167
+ {
168
+ "file": "captured_images/2024-05-06/image_18-45-15.png",
169
+ "text": "The man is holding a flap disc, which is a type of abrasive wheel used for grinding, smoothing, and finishing metal surfaces.",
170
+ "new_name": "new_names/flap_disc.png"
171
+ }
172
+ ]
new_names/adjustable_wrench.png ADDED
new_names/bike_hex_wrench_set.png ADDED
new_names/black_sliding_T-bevel_with_red_handles.png ADDED
new_names/c_clamp.png ADDED
new_names/claw_hammer.png ADDED
new_names/coping_saw.png ADDED
new_names/crowbar.png ADDED
new_names/digital_caliper.png ADDED
new_names/flap_disc.png ADDED
new_names/flat_paintbrush_yellow_handle_black_bristles.png ADDED
new_names/flexible_drill_bit_extension.png ADDED
new_names/folding_ruler.png ADDED
new_names/locking_pliers.png ADDED
new_names/metal_file_red_handle.png ADDED
new_names/nut_driver.png ADDED
new_names/power_cord.png ADDED
new_names/putty_knife.png ADDED
new_names/red_capped_permanent_marker.png ADDED
new_names/scissors.png ADDED
new_names/screwdriver.png ADDED
new_names/slip_joint_plier.png ADDED
new_names/slip_joint_pliers.png ADDED
new_names/small_screwdriver.png ADDED
new_names/socket_wrench.png ADDED
new_names/spanner_wrench.png ADDED
new_names/staple_gun.png ADDED
new_names/torque_wrench.png ADDED
new_names/vernier_caliper.png ADDED
new_names/voltage_tester_screwdriver.png ADDED
new_names/white_adhesive_tape.png ADDED
new_names/wood_chisel.png ADDED
new_names/yellow_black_screwdriver.png ADDED
new_names/yellow_black_torx_T5_screwdriver.png ADDED
requirements.txt ADDED
Binary file (2.76 kB). View file