Spaces:
Running
Running
ai-puppy
commited on
Commit
Β·
879668d
1
Parent(s):
4e7bcf3
save
Browse files
app.py
CHANGED
@@ -23,15 +23,25 @@ uploaded_file_path = None
|
|
23 |
|
24 |
# Chat functionality removed - focusing on file analysis
|
25 |
|
|
|
|
|
|
|
|
|
26 |
def handle_file_upload(file):
|
27 |
"""Handle file upload and store the path globally"""
|
28 |
global uploaded_file_path
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
uploaded_file_path = None
|
34 |
-
return "β
|
35 |
|
36 |
def analyze_file_with_question(user_question):
|
37 |
"""
|
@@ -39,13 +49,13 @@ def analyze_file_with_question(user_question):
|
|
39 |
"""
|
40 |
global uploaded_file_path
|
41 |
|
42 |
-
if not uploaded_file_path or not os.path.exists(uploaded_file_path):
|
43 |
-
return "β No file uploaded or file not found. Please upload a file first."
|
44 |
-
|
45 |
-
if not user_question or user_question.strip() == "":
|
46 |
-
user_question = "Provide a comprehensive analysis of this file including security, performance, and data insights."
|
47 |
-
|
48 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
# Use the new guided analysis approach
|
50 |
result = analyze_file_with_guidance_sync(uploaded_file_path, user_question)
|
51 |
return result
|
@@ -80,8 +90,7 @@ with gr.Blocks(title="DataForge - AI-Powered File Analysis") as demo:
|
|
80 |
gr.Markdown("### π€ File Upload")
|
81 |
file_upload = gr.File(
|
82 |
label="Upload File for Analysis",
|
83 |
-
file_types=[".txt", ".log", ".csv", ".json", ".xml", ".py", ".js", ".html", ".md"]
|
84 |
-
type="filepath"
|
85 |
)
|
86 |
upload_status = gr.Textbox(
|
87 |
label="Upload Status",
|
@@ -121,16 +130,16 @@ with gr.Blocks(title="DataForge - AI-Powered File Analysis") as demo:
|
|
121 |
)
|
122 |
|
123 |
# Event handlers
|
124 |
-
file_upload.
|
125 |
fn=handle_file_upload,
|
126 |
-
inputs=
|
127 |
-
outputs=
|
128 |
)
|
129 |
|
130 |
analyze_btn.click(
|
131 |
fn=analyze_file_with_question,
|
132 |
-
inputs=
|
133 |
-
outputs=
|
134 |
)
|
135 |
|
136 |
gr.Markdown("---")
|
@@ -179,4 +188,10 @@ with gr.Blocks(title="DataForge - AI-Powered File Analysis") as demo:
|
|
179 |
""")
|
180 |
|
181 |
if __name__ == "__main__":
|
182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Chat functionality removed - focusing on file analysis
|
25 |
|
26 |
+
def test_function():
|
27 |
+
"""Simple test function to verify Gradio API binding works"""
|
28 |
+
return "β
API binding test successful!"
|
29 |
+
|
30 |
def handle_file_upload(file):
|
31 |
"""Handle file upload and store the path globally"""
|
32 |
global uploaded_file_path
|
33 |
+
try:
|
34 |
+
if file is not None:
|
35 |
+
# Gradio File component returns the file path directly
|
36 |
+
uploaded_file_path = file
|
37 |
+
filename = os.path.basename(file)
|
38 |
+
return f"β
File uploaded successfully: {filename}"
|
39 |
+
else:
|
40 |
+
uploaded_file_path = None
|
41 |
+
return "β No file uploaded"
|
42 |
+
except Exception as e:
|
43 |
uploaded_file_path = None
|
44 |
+
return f"β Upload error: {str(e)}"
|
45 |
|
46 |
def analyze_file_with_question(user_question):
|
47 |
"""
|
|
|
49 |
"""
|
50 |
global uploaded_file_path
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
try:
|
53 |
+
if not uploaded_file_path or not os.path.exists(uploaded_file_path):
|
54 |
+
return "β No file uploaded or file not found. Please upload a file first."
|
55 |
+
|
56 |
+
if not user_question or user_question.strip() == "":
|
57 |
+
user_question = "Provide a comprehensive analysis of this file including security, performance, and data insights."
|
58 |
+
|
59 |
# Use the new guided analysis approach
|
60 |
result = analyze_file_with_guidance_sync(uploaded_file_path, user_question)
|
61 |
return result
|
|
|
90 |
gr.Markdown("### π€ File Upload")
|
91 |
file_upload = gr.File(
|
92 |
label="Upload File for Analysis",
|
93 |
+
file_types=[".txt", ".log", ".csv", ".json", ".xml", ".py", ".js", ".html", ".md"]
|
|
|
94 |
)
|
95 |
upload_status = gr.Textbox(
|
96 |
label="Upload Status",
|
|
|
130 |
)
|
131 |
|
132 |
# Event handlers
|
133 |
+
file_upload.upload(
|
134 |
fn=handle_file_upload,
|
135 |
+
inputs=file_upload,
|
136 |
+
outputs=upload_status
|
137 |
)
|
138 |
|
139 |
analyze_btn.click(
|
140 |
fn=analyze_file_with_question,
|
141 |
+
inputs=user_question,
|
142 |
+
outputs=analysis_output
|
143 |
)
|
144 |
|
145 |
gr.Markdown("---")
|
|
|
188 |
""")
|
189 |
|
190 |
if __name__ == "__main__":
|
191 |
+
print("Starting DataForge application...")
|
192 |
+
try:
|
193 |
+
demo.launch(server_name="127.0.0.1", server_port=7860)
|
194 |
+
except Exception as e:
|
195 |
+
print(f"Error launching app: {e}")
|
196 |
+
# Fallback launch
|
197 |
+
demo.launch()
|