Kevin Louis commited on
Commit
e6cc6ba
1 Parent(s): 1a17f8d

Update app.py

Browse files

Update app to include graphic response

Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -3,13 +3,17 @@ from huggingface_hub import CommitScheduler
3
  from datasets import Dataset
4
  import gradio as gr
5
  import pandas as pd
 
6
  import os
7
 
8
- from parameter_extractor import ParameterExtractor
9
  from DNAseq import DNAseq
 
 
 
10
  from helper import list_at_index_0, list_at_index_1
11
  from logger import cts_log_file_create, logger, cts_logger
12
 
 
13
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
14
 
15
  # Create csv file for data logging
@@ -29,7 +33,6 @@ scheduler = CommitScheduler(
29
 
30
  def chat_to_sequence(sequence, user_query):
31
 
32
-
33
  # Sequence to be analysed/queried
34
  input_sequence = sequence
35
 
@@ -48,8 +51,11 @@ def chat_to_sequence(sequence, user_query):
48
  # Set ParameterExtractor class expected variable
49
  query = user_query
50
 
51
- # Bot Response
52
- response = ""
 
 
 
53
 
54
  # Query Code Description Message
55
  code_descript_message = ''
@@ -151,7 +157,13 @@ def chat_to_sequence(sequence, user_query):
151
  # Check if there is a match
152
  if not matching_row.empty:
153
  function = matching_row.iloc[0]["function"]
154
- response = str(eval(function))
 
 
 
 
 
 
155
  code_descript_message = query_code_description.title()
156
  cts_logger(scheduler, log_file_path, log_data, response)
157
  else:
@@ -160,8 +172,8 @@ def chat_to_sequence(sequence, user_query):
160
  cts_logger(scheduler, log_file_path, log_data, response)
161
  print("No matching code found for the function:", code)
162
 
163
- return response, code_descript_message
164
- return response, code_descript_message
165
 
166
 
167
  ChatToSequence = gr.Interface(
@@ -184,6 +196,8 @@ ChatToSequence = gr.Interface(
184
  "What are the bases from position 2 to 10"],
185
  ["ggcattgaggagaccattgacaccgtcattagcaatgcactacaactgtcacaacctaaa",
186
  "How many bases are there from position 2 to 10"],
 
 
187
  ],
188
  ).queue()
189
 
 
3
  from datasets import Dataset
4
  import gradio as gr
5
  import pandas as pd
6
+ import plotly.graph_objects as go
7
  import os
8
 
 
9
  from DNAseq import DNAseq
10
+ from grapher import DNAgrapher
11
+ from parameter_extractor import ParameterExtractor
12
+
13
  from helper import list_at_index_0, list_at_index_1
14
  from logger import cts_log_file_create, logger, cts_logger
15
 
16
+
17
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
18
 
19
  # Create csv file for data logging
 
33
 
34
  def chat_to_sequence(sequence, user_query):
35
 
 
36
  # Sequence to be analysed/queried
37
  input_sequence = sequence
38
 
 
51
  # Set ParameterExtractor class expected variable
52
  query = user_query
53
 
54
+ # Initialise Graphic Response
55
+ fig = None
56
+
57
+ # Initialise Text Response
58
+ response = None
59
 
60
  # Query Code Description Message
61
  code_descript_message = ''
 
157
  # Check if there is a match
158
  if not matching_row.empty:
159
  function = matching_row.iloc[0]["function"]
160
+ f_response = eval(function)
161
+ if code[0] == 'c':
162
+ response = None
163
+ fig = go.Figure(f_response)
164
+ else:
165
+ response = str(f_response)
166
+ fig = None
167
  code_descript_message = query_code_description.title()
168
  cts_logger(scheduler, log_file_path, log_data, response)
169
  else:
 
172
  cts_logger(scheduler, log_file_path, log_data, response)
173
  print("No matching code found for the function:", code)
174
 
175
+ return response, fig, code_descript_message
176
+ return response, fig, code_descript_message
177
 
178
 
179
  ChatToSequence = gr.Interface(
 
196
  "What are the bases from position 2 to 10"],
197
  ["ggcattgaggagaccattgacaccgtcattagcaatgcactacaactgtcacaacctaaa",
198
  "How many bases are there from position 2 to 10"],
199
+ ["ggcattgaggagaccattgacaccgtcattagcaatgcactacaactgtcacaacctaaa",
200
+ "Show pie chart of total bases"],
201
  ],
202
  ).queue()
203