Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -2,113 +2,112 @@ import os
|
|
2 |
import sys
|
3 |
import traceback
|
4 |
import gradio as gr
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
try:
|
9 |
-
|
10 |
-
|
11 |
-
except ImportError as e:
|
12 |
-
return False, f"Failed to import {module_name}: {str(e)}"
|
13 |
except Exception as e:
|
14 |
-
|
15 |
-
|
16 |
-
def test_imports():
|
17 |
-
# Create a report of all import attempts
|
18 |
-
results = []
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
results.append(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
#
|
28 |
try:
|
29 |
-
from
|
30 |
-
|
31 |
-
results.append("β Model tokenizer accessible")
|
32 |
except Exception as e:
|
33 |
-
results.append(f"
|
34 |
|
35 |
-
# Test vector store
|
36 |
try:
|
37 |
-
from langchain.
|
38 |
-
|
39 |
-
results.append("β Vector store components accessible")
|
40 |
except Exception as e:
|
41 |
-
results.append(f"
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
size = os.path.getsize(pdf_file) / (1024 * 1024) # Size in MB
|
55 |
-
results.append(f"{pdf_file}: Found ({size:.2f} MB)")
|
56 |
|
57 |
-
# Try
|
58 |
try:
|
59 |
-
import
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
text_sample = reader.pages[0].extract_text()[:100] + "..."
|
64 |
-
results.append(f"- Pages: {num_pages}")
|
65 |
-
results.append(f"- Sample text: {text_sample}")
|
66 |
-
except Exception as e:
|
67 |
-
results.append(f"- Error reading file: {str(e)}")
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
def check_environment():
|
72 |
-
"""Get information about the Python environment"""
|
73 |
-
results = []
|
74 |
-
|
75 |
-
results.append(f"Python version: {sys.version}")
|
76 |
-
results.append(f"Python executable: {sys.executable}")
|
77 |
-
results.append(f"Working directory: {os.getcwd()}")
|
78 |
-
|
79 |
-
# List all installed packages
|
80 |
try:
|
81 |
import pkg_resources
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
85 |
except:
|
86 |
-
results.append("Could not
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
return "\n".join(results)
|
89 |
|
90 |
def main():
|
91 |
-
with gr.Blocks(title="
|
92 |
-
gr.Markdown("# Vision 2030 Assistant -
|
93 |
-
gr.Markdown("This interface helps identify import and initialization issues.")
|
94 |
-
|
95 |
-
with gr.Tab("Import Testing"):
|
96 |
-
test_btn = gr.Button("Test Imports")
|
97 |
-
import_results = gr.Textbox(label="Import Test Results", lines=20)
|
98 |
-
|
99 |
-
test_btn.click(test_imports, inputs=[], outputs=[import_results])
|
100 |
|
101 |
-
|
102 |
-
|
103 |
-
pdf_results = gr.Textbox(label="PDF Test Results", lines=20)
|
104 |
-
|
105 |
-
pdf_btn.click(check_pdfs, inputs=[], outputs=[pdf_results])
|
106 |
|
107 |
-
|
108 |
-
env_btn = gr.Button("Check Environment")
|
109 |
-
env_results = gr.Textbox(label="Environment Information", lines=30)
|
110 |
-
|
111 |
-
env_btn.click(check_environment, inputs=[], outputs=[env_results])
|
112 |
|
113 |
interface.launch()
|
114 |
|
|
|
2 |
import sys
|
3 |
import traceback
|
4 |
import gradio as gr
|
5 |
+
import spaces
|
6 |
|
7 |
+
@spaces.GPU
|
8 |
+
def test_all_imports():
|
9 |
+
results = []
|
10 |
+
|
11 |
+
# Test basic imports
|
12 |
+
for lib_name in [
|
13 |
+
"torch",
|
14 |
+
"numpy",
|
15 |
+
"pandas",
|
16 |
+
"PyPDF2",
|
17 |
+
"transformers",
|
18 |
+
"sentence_transformers"
|
19 |
+
]:
|
20 |
+
try:
|
21 |
+
__import__(lib_name)
|
22 |
+
results.append(f"β
{lib_name}: Successfully imported")
|
23 |
+
except Exception as e:
|
24 |
+
results.append(f"β {lib_name}: Error - {str(e)}")
|
25 |
+
|
26 |
+
# Test langchain imports specifically
|
27 |
try:
|
28 |
+
import langchain
|
29 |
+
results.append(f"β
langchain: Successfully imported (version {langchain.__version__})")
|
|
|
|
|
30 |
except Exception as e:
|
31 |
+
results.append(f"β langchain: Error - {str(e)}")
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
# Test langchain_community imports
|
34 |
+
try:
|
35 |
+
import langchain_community
|
36 |
+
results.append(f"β
langchain_community: Successfully imported")
|
37 |
+
except Exception as e:
|
38 |
+
results.append(f"β langchain_community: Error - {str(e)}")
|
39 |
+
|
40 |
+
# Try alternative import format
|
41 |
+
try:
|
42 |
+
import langchain.community
|
43 |
+
results.append(f"β
langchain.community: Successfully imported")
|
44 |
+
except Exception as e2:
|
45 |
+
results.append(f"β langchain.community: Error - {str(e2)}")
|
46 |
|
47 |
+
# Test specific langchain imports that might be failing
|
48 |
try:
|
49 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
50 |
+
results.append(f"β
langchain.text_splitter: Successfully imported")
|
|
|
51 |
except Exception as e:
|
52 |
+
results.append(f"β langchain.text_splitter: Error - {str(e)}")
|
53 |
|
|
|
54 |
try:
|
55 |
+
from langchain.schema import Document
|
56 |
+
results.append(f"β
langchain.schema: Successfully imported")
|
|
|
57 |
except Exception as e:
|
58 |
+
results.append(f"β langchain.schema: Error - {str(e)}")
|
59 |
|
60 |
+
try:
|
61 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
62 |
+
results.append(f"β
langchain.embeddings: Successfully imported")
|
63 |
+
except Exception as e:
|
64 |
+
results.append(f"β langchain.embeddings: Error - {str(e)}")
|
65 |
|
66 |
+
try:
|
67 |
+
from langchain_community.vectorstores import FAISS
|
68 |
+
results.append(f"β
langchain_community.vectorstores: Successfully imported")
|
69 |
+
except Exception as e:
|
70 |
+
results.append(f"β langchain_community.vectorstores: Error - {str(e)}")
|
|
|
|
|
71 |
|
72 |
+
# Try alternative import
|
73 |
try:
|
74 |
+
from langchain.vectorstores import FAISS
|
75 |
+
results.append(f"β
langchain.vectorstores: Successfully imported")
|
76 |
+
except Exception as e2:
|
77 |
+
results.append(f"β langchain.vectorstores: Error - {str(e2)}")
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
+
# Check installed package versions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
try:
|
81 |
import pkg_resources
|
82 |
+
results.append("\nπ¦ Installed Packages:")
|
83 |
+
for package in ["langchain", "langchain-community", "transformers", "sentence-transformers"]:
|
84 |
+
try:
|
85 |
+
version = pkg_resources.get_distribution(package).version
|
86 |
+
results.append(f" - {package}: {version}")
|
87 |
+
except:
|
88 |
+
results.append(f" - {package}: Not installed")
|
89 |
except:
|
90 |
+
results.append("β Could not check installed packages")
|
91 |
+
|
92 |
+
# Check PDF files
|
93 |
+
results.append("\nπ PDF Files:")
|
94 |
+
for pdf_file in ["saudi_vision203.pdf", "saudi_vision2030_ar.pdf"]:
|
95 |
+
if os.path.exists(pdf_file):
|
96 |
+
size = os.path.getsize(pdf_file) / (1024 * 1024) # MB
|
97 |
+
results.append(f" - {pdf_file}: Found ({size:.2f} MB)")
|
98 |
+
else:
|
99 |
+
results.append(f" - {pdf_file}: Not found")
|
100 |
|
101 |
return "\n".join(results)
|
102 |
|
103 |
def main():
|
104 |
+
with gr.Blocks(title="Import Diagnosis") as interface:
|
105 |
+
gr.Markdown("# Vision 2030 Assistant - Import Error Diagnosis")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
+
test_button = gr.Button("Test All Imports")
|
108 |
+
results_box = gr.Textbox(label="Results", lines=30)
|
|
|
|
|
|
|
109 |
|
110 |
+
test_button.click(test_all_imports, inputs=[], outputs=[results_box])
|
|
|
|
|
|
|
|
|
111 |
|
112 |
interface.launch()
|
113 |
|