Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -116,46 +116,6 @@ img_interface = gr.Interface(
|
|
116 |
title="AI Image Question Answering"
|
117 |
)
|
118 |
|
119 |
-
# β
Data Visualization Function
|
120 |
-
def generate_visualization(excel_file, viz_type, user_request):
|
121 |
-
try:
|
122 |
-
df = pd.read_excel(excel_file)
|
123 |
-
df = df.astype(str).fillna("")
|
124 |
-
|
125 |
-
table_input = {
|
126 |
-
"table": df.to_dict(orient="records"),
|
127 |
-
"query": user_request.strip() if isinstance(user_request, str) else "What is the summary?"
|
128 |
-
}
|
129 |
-
|
130 |
-
table_answer = table_analyzer(**table_input)
|
131 |
-
|
132 |
-
prompt = (
|
133 |
-
f"Given a dataset with columns {list(df.columns)}, generate Python code using Matplotlib and Seaborn "
|
134 |
-
f"to create a {viz_type.lower()} based on: {user_request}. Only return valid Python code, no explanations."
|
135 |
-
)
|
136 |
-
code_response = code_generator(prompt, max_new_tokens=150, do_sample=True)
|
137 |
-
|
138 |
-
if isinstance(code_response, list) and "generated_text" in code_response[0]:
|
139 |
-
generated_code = code_response[0]["generated_text"]
|
140 |
-
else:
|
141 |
-
generated_code = "Error: Model did not return valid code."
|
142 |
-
|
143 |
-
try:
|
144 |
-
exec_globals = {"plt": plt, "sns": sns, "pd": pd, "df": df, "io": io}
|
145 |
-
exec(generated_code, exec_globals)
|
146 |
-
|
147 |
-
fig = plt.gcf()
|
148 |
-
img_buf = io.BytesIO()
|
149 |
-
fig.savefig(img_buf, format='png')
|
150 |
-
img_buf.seek(0)
|
151 |
-
plt.close(fig)
|
152 |
-
except Exception as e:
|
153 |
-
return generated_code, f"Error in executing visualization: {str(e)}"
|
154 |
-
|
155 |
-
return generated_code, img_buf
|
156 |
-
|
157 |
-
except Exception as e:
|
158 |
-
return f"Error: {str(e)}", "Failed to analyze table."
|
159 |
|
160 |
# β
Gradio UI for Data Visualization
|
161 |
viz_interface = gr.Interface(
|
@@ -170,7 +130,7 @@ viz_interface = gr.Interface(
|
|
170 |
)
|
171 |
|
172 |
# β
Mount Gradio Interfaces
|
173 |
-
demo = gr.TabbedInterface([doc_interface, img_interface
|
174 |
app = gr.mount_gradio_app(app, demo, path="/")
|
175 |
|
176 |
@app.get("/")
|
|
|
116 |
title="AI Image Question Answering"
|
117 |
)
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
# β
Gradio UI for Data Visualization
|
121 |
viz_interface = gr.Interface(
|
|
|
130 |
)
|
131 |
|
132 |
# β
Mount Gradio Interfaces
|
133 |
+
demo = gr.TabbedInterface([doc_interface, img_interface], ["Document QA", "Image QA"])
|
134 |
app = gr.mount_gradio_app(app, demo, path="/")
|
135 |
|
136 |
@app.get("/")
|