ericjohnson97 commited on
Commit
3b45de9
·
1 Parent(s): 6255f8a
Files changed (4) hide show
  1. .gitignore +3 -1
  2. README.md +37 -0
  3. llm/gptPlotCreator.py +6 -5
  4. llm_plot.py +4 -3
.gitignore CHANGED
@@ -1,2 +1,4 @@
1
  .env
2
- *.pyc
 
 
 
1
  .env
2
+ *.pyc
3
+ plot.py
4
+ plot.png
README.md ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # GPT_MAVPlot
2
+
3
+ MAVPlot is a Python-based project which uses Gradio as an interface and GPT-X powered by OpenAI as a chatbot to generate and plot MAVLink data. It provides an easy-to-use, chatbot-like interface for users to describe the plot they would like to generate.
4
+
5
+ ## Installation
6
+
7
+ 1. Clone the repository:
8
+
9
+ ```shell
10
+ git clone https://github.com/yourusername/mavplot.git
11
+ ```
12
+
13
+ 2. Install the requirements:
14
+
15
+ ```shell
16
+ pip install -r requirements.txt
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ After installing all dependencies, run the main script using:
22
+
23
+ ```shell
24
+ python llm_plot.py
25
+ ```
26
+
27
+ A web-based Gradio interface will launch. You can then input the description of the plot you would like to generate in the textbox, or upload a file.
28
+
29
+ The chatbot will process your request and generate the corresponding plot, which will be displayed in the chat interface.
30
+
31
+ ## Contributing
32
+
33
+ Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.
34
+
35
+ ## License
36
+
37
+ [MIT](https://choosealicense.com/licenses/mit/)
llm/gptPlotCreator.py CHANGED
@@ -44,8 +44,8 @@ class PlotCreator:
44
 
45
  @staticmethod
46
  def extract_code_snippets(text):
47
- pattern = r'```(.*?)```'
48
- snippets = re.findall(pattern, text, re.DOTALL)
49
  if len(snippets) == 0:
50
  snippets = [text]
51
  return snippets
@@ -76,6 +76,7 @@ class PlotCreator:
76
 
77
  # run the script
78
  os.system("python plot.py")
 
79
 
80
  def create_plot(self, human_input):
81
  file = "data/2023-01-04 20-51-25.tlog"
@@ -95,9 +96,9 @@ class PlotCreator:
95
  subprocess.check_output(["python", "plot.py"], stderr=subprocess.STDOUT)
96
  except subprocess.CalledProcessError as e:
97
  print(e.output.decode())
98
- self.attempt_to_fix_sctript("plot.py", e.output.decode())
99
  except Exception as e:
100
  print(e)
101
- self.attempt_to_fix_sctript("plot.py", str(e))
102
 
103
- return ("plot.png", None)
 
44
 
45
  @staticmethod
46
  def extract_code_snippets(text):
47
+ pattern = r'```.*?\n(.*?)```'
48
+ snippets = re.findall(pattern, text, re.DOTALL | re.MULTILINE)
49
  if len(snippets) == 0:
50
  snippets = [text]
51
  return snippets
 
76
 
77
  # run the script
78
  os.system("python plot.py")
79
+ return code
80
 
81
  def create_plot(self, human_input):
82
  file = "data/2023-01-04 20-51-25.tlog"
 
96
  subprocess.check_output(["python", "plot.py"], stderr=subprocess.STDOUT)
97
  except subprocess.CalledProcessError as e:
98
  print(e.output.decode())
99
+ code = self.attempt_to_fix_sctript("plot.py", e.output.decode())
100
  except Exception as e:
101
  print(e)
102
+ code = self.attempt_to_fix_sctript("plot.py", str(e))
103
 
104
+ return [("plot.png", None), code[0]]
llm_plot.py CHANGED
@@ -18,15 +18,16 @@ def bot(history):
18
  # Check if it is a string
19
  if isinstance(user_input, str):
20
  # Generate the plot
21
- img = plot_creator.create_plot(user_input)
22
- response = img
23
  else:
24
  response = "**That's cool!**"
25
 
26
- history[-1][1] = ('plot.png', None)
 
27
  return history
28
 
29
  with gr.Blocks() as demo:
 
30
  chatbot = gr.Chatbot([], elem_id="chatbot").style(height=750)
31
 
32
  with gr.Row():
 
18
  # Check if it is a string
19
  if isinstance(user_input, str):
20
  # Generate the plot
21
+ response = plot_creator.create_plot(user_input)
 
22
  else:
23
  response = "**That's cool!**"
24
 
25
+ history[-1][1] = response[0]
26
+ history = history + [(None, f"Here is the code used to generate the plot:\n```\n{response[1]}```")]
27
  return history
28
 
29
  with gr.Blocks() as demo:
30
+ gr.Markdown("# GPT MAVPlot\n\nThis web-based tool allows users to upload mavlink tlogs in which the chat bot will use to generate plots from. It does this by creating a python script using pymavlink and matplotlib. The output includes the plot and the code used to generate it. ")
31
  chatbot = gr.Chatbot([], elem_id="chatbot").style(height=750)
32
 
33
  with gr.Row():