hertogateis commited on
Commit
0dea963
·
verified ·
1 Parent(s): d41df51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -30
app.py CHANGED
@@ -70,37 +70,36 @@ else:
70
  # Ensure the question is a string
71
  if not isinstance(question, str):
72
  st.error("The question input is not a valid string.")
73
- return
74
-
75
- # Use TAPAS model to process the question
76
- result = tqa(table=df, query=question)
77
-
78
- # Check if TAPAS is returning the expected answer
79
- answer = result['answer']
80
- st.write(f"TAPAS Answer: {answer}")
81
-
82
- # Determine if the question relates to graph generation
83
- if 'between' in question.lower() and 'and' in question.lower():
84
- # This is a request for a scatter plot (two columns)
85
- columns = question.split('between')[-1].split('and')
86
- columns = [col.strip() for col in columns]
87
- if len(columns) == 2 and all(col in df.columns for col in columns):
88
- fig = px.scatter(df, x=columns[0], y=columns[1], title=f"Scatter Plot between {columns[0]} and {columns[1]}")
89
- st.plotly_chart(fig, use_container_width=True)
90
- st.success(f"Here is the scatter plot between '{columns[0]}' and '{columns[1]}'.")
91
- else:
92
- st.warning("Columns not found in the dataset.")
93
- elif 'column' in question.lower():
94
- # This is a request for a line graph (single column)
95
- column = question.split('of')[-1].strip() # Handle 'of' keyword
96
- if column in df.columns:
97
- fig = px.line(df, x=df.index, y=column, title=f"Graph of column '{column}'")
98
- st.plotly_chart(fig, use_container_width=True)
99
- st.success(f"Here is the graph of column '{column}'.")
100
- else:
101
- st.warning(f"Column '{column}' not found in the data.")
102
  else:
103
- st.warning("Please ask a valid graph-related question (e.g., 'make a graph between column1 and column2').")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
  except Exception as e:
106
  st.warning(f"Error processing question or generating graph: {str(e)}")
 
70
  # Ensure the question is a string
71
  if not isinstance(question, str):
72
  st.error("The question input is not a valid string.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  else:
74
+ # Use TAPAS model to process the question
75
+ result = tqa(table=df, query=question)
76
+
77
+ # Check if TAPAS is returning the expected answer
78
+ answer = result['answer']
79
+ st.write(f"TAPAS Answer: {answer}")
80
+
81
+ # Determine if the question relates to graph generation
82
+ if 'between' in question.lower() and 'and' in question.lower():
83
+ # This is a request for a scatter plot (two columns)
84
+ columns = question.split('between')[-1].split('and')
85
+ columns = [col.strip() for col in columns]
86
+ if len(columns) == 2 and all(col in df.columns for col in columns):
87
+ fig = px.scatter(df, x=columns[0], y=columns[1], title=f"Scatter Plot between {columns[0]} and {columns[1]}")
88
+ st.plotly_chart(fig, use_container_width=True)
89
+ st.success(f"Here is the scatter plot between '{columns[0]}' and '{columns[1]}'.")
90
+ else:
91
+ st.warning("Columns not found in the dataset.")
92
+ elif 'column' in question.lower():
93
+ # This is a request for a line graph (single column)
94
+ column = question.split('of')[-1].strip() # Handle 'of' keyword
95
+ if column in df.columns:
96
+ fig = px.line(df, x=df.index, y=column, title=f"Graph of column '{column}'")
97
+ st.plotly_chart(fig, use_container_width=True)
98
+ st.success(f"Here is the graph of column '{column}'.")
99
+ else:
100
+ st.warning(f"Column '{column}' not found in the data.")
101
+ else:
102
+ st.warning("Please ask a valid graph-related question (e.g., 'make a graph between column1 and column2').")
103
 
104
  except Exception as e:
105
  st.warning(f"Error processing question or generating graph: {str(e)}")