hertogateis commited on
Commit
2279e40
·
verified ·
1 Parent(s): 379de3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -46
app.py CHANGED
@@ -62,53 +62,67 @@ else:
62
  # User input for the question
63
  question = st.text_input(f'Ask your graph-related question in {language}')
64
 
65
- with st.spinner():
66
- if st.button('Generate Graph'):
67
- try:
68
- # Check if the question is a valid string (not empty or None)
69
- if not question or not isinstance(question, str):
70
- st.error("Please enter a valid question in the form of text.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  else:
72
- # Use TAPAS model to process the question
73
- result = tqa(table=df, query=question)
74
-
75
- # Debugging: Output TAPAS raw response
76
- st.write("TAPAS Raw Output (Response):")
77
- st.write(result) # Show the raw output from TAPAS
78
-
79
- # Optionally, you can output the raw output as plain text:
80
- st.text("Raw TAPAS Output (Plain Text):")
81
- st.text(str(result)) # Show raw output as plain text
82
-
83
- # Check if TAPAS is returning the expected answer
84
- answer = result.get('answer', None)
85
- if answer:
86
- st.write(f"TAPAS Answer: {answer}")
 
 
 
 
 
 
87
  else:
88
- st.warning("TAPAS did not return a valid answer.")
89
-
90
- # Determine if the question relates to graph generation
91
- if 'between' in question.lower() and 'and' in question.lower():
92
- # This is a request for a scatter plot (two columns)
93
- columns = question.split('between')[-1].split('and')
94
- columns = [col.strip() for col in columns]
95
- if len(columns) == 2 and all(col in df.columns for col in columns):
96
- fig = px.scatter(df, x=columns[0], y=columns[1], title=f"Scatter Plot between {columns[0]} and {columns[1]}")
97
- st.plotly_chart(fig, use_container_width=True)
98
- st.success(f"Here is the scatter plot between '{columns[0]}' and '{columns[1]}'.")
99
- else:
100
- st.warning("Columns not found in the dataset.")
101
- elif 'column' in question.lower():
102
- # This is a request for a line graph (single column)
103
- column = question.split('of')[-1].strip() # Handle 'of' keyword
104
- if column in df.columns:
105
- fig = px.line(df, x=df.index, y=column, title=f"Graph of column '{column}'")
106
- st.plotly_chart(fig, use_container_width=True)
107
- st.success(f"Here is the graph of column '{column}'.")
108
- else:
109
- st.warning(f"Column '{column}' not found in the data.")
110
  else:
111
- st.warning("Please ask a valid graph-related question (e.g., 'make a graph between column1 and column2').")
 
 
112
 
113
- except Exception as e:
114
- st.warning(f"Error processing question or generating graph: {str(e)}")
 
62
  # User input for the question
63
  question = st.text_input(f'Ask your graph-related question in {language}')
64
 
65
+ with st.spinner():
66
+ if st.button('Generate Graph'):
67
+ try:
68
+ # Ensure the question is a valid string
69
+ if not question or not isinstance(question, str):
70
+ st.error("Please enter a valid question in the form of text.")
71
+ else:
72
+ # Use TAPAS model to process the question
73
+ result = tqa(table=df, query=question)
74
+
75
+ # Display the raw output from TAPAS
76
+ st.write("TAPAS Raw Output (Response):")
77
+ st.write(result) # This will display the raw output from TAPAS
78
+
79
+ # Optionally, you can output the raw output as plain text:
80
+ st.text("Raw TAPAS Output (Plain Text):")
81
+ st.text(str(result)) # This will display raw output as plain text
82
+
83
+ # Check if TAPAS is returning the expected answer
84
+ answer = result.get('answer', None)
85
+ if answer:
86
+ st.write(f"TAPAS Answer: {answer}")
87
  else:
88
+ st.warning("TAPAS did not return a valid answer.")
89
+
90
+ # Determine if the question relates to graph generation
91
+ if 'between' in question.lower() and 'and' in question.lower():
92
+ # This is a request for a scatter plot (two columns)
93
+ columns = question.split('between')[-1].split('and')
94
+ columns = [col.strip() for col in columns]
95
+ if len(columns) == 2 and all(col in df.columns for col in columns):
96
+ # Prepare the data for Plotly (scatter plot)
97
+ x_data = df[columns[0]].dropna() # Extract x column, drop NaN values
98
+ y_data = df[columns[1]].dropna() # Extract y column, drop NaN values
99
+
100
+ # Ensure x_data and y_data have the same length
101
+ min_length = min(len(x_data), len(y_data))
102
+ x_data = x_data[:min_length]
103
+ y_data = y_data[:min_length]
104
+
105
+ # Create the scatter plot
106
+ fig = px.scatter(x=x_data, y=y_data, title=f"Scatter Plot between {columns[0]} and {columns[1]}")
107
+ st.plotly_chart(fig, use_container_width=True)
108
+ st.success(f"Here is the scatter plot between '{columns[0]}' and '{columns[1]}'.")
109
  else:
110
+ st.warning("Columns not found in the dataset or the question format is incorrect.")
111
+ elif 'column' in question.lower():
112
+ # This is a request for a line graph (single column)
113
+ column = question.split('of')[-1].strip() # Handle 'of' keyword
114
+ if column in df.columns:
115
+ # Prepare the data for Plotly (line graph)
116
+ column_data = df[column].dropna() # Drop NaN values
117
+
118
+ # Create the line plot
119
+ fig = px.line(x=column_data.index, y=column_data, title=f"Graph of column '{column}'")
120
+ st.plotly_chart(fig, use_container_width=True)
121
+ st.success(f"Here is the graph of column '{column}'.")
 
 
 
 
 
 
 
 
 
 
122
  else:
123
+ st.warning(f"Column '{column}' not found in the data.")
124
+ else:
125
+ st.warning("Please ask a valid graph-related question (e.g., 'make a graph between column1 and column2').")
126
 
127
+ except Exception as e:
128
+ st.warning(f"Error processing question or generating graph: {str(e)}")