Quazim0t0 commited on
Commit
bb29d2e
·
verified ·
1 Parent(s): a6f506b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -24
app.py CHANGED
@@ -7,52 +7,78 @@ agent = CodeAgent(
7
  model=HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct"),
8
  )
9
 
10
- def analyze_content(file_paths):
11
- """Process files and generate comprehensive report"""
 
12
  full_content = []
13
 
14
- for path in file_paths:
 
 
15
  try:
16
  with open(path, 'r', encoding='utf-8') as f:
17
  content = f.read()
18
- full_content.append(f"--- {path.split('/')[-1]} ---\n{content}")
19
  except Exception as e:
20
  return f"Error processing {path}: {str(e)}"
21
-
 
 
22
  report = agent.run(f"""
23
  Analyze these documents and create a detailed report:
24
 
25
- {''.join(full_content)[:10000]} # First 10k characters
26
 
27
- Report should include:
28
- 1. Key themes and patterns
29
- 2. Important relationships
30
- 3. Contextual insights
31
- 4. Actionable recommendations
32
 
33
- Use professional markdown formatting with headings.
34
  """)
35
 
 
36
  return report
37
 
38
  with gr.Blocks() as demo:
39
- gr.Markdown("# Document Analysis System")
40
 
41
  with gr.Row():
42
- file_input = gr.File(
43
- file_count="multiple",
44
- file_types=[".txt"],
45
- label="Upload Documents"
46
- )
47
- process_btn = gr.Button("Generate Report", variant="primary")
48
-
49
- report_output = gr.Markdown(label="Analysis Report")
 
 
 
 
 
 
 
 
50
 
51
- process_btn.click(
52
- fn=analyze_content,
53
  inputs=file_input,
54
- outputs=report_output
55
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  if __name__ == "__main__":
58
  demo.launch(
 
7
  model=HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct"),
8
  )
9
 
10
+ def analyze_content(file_paths, progress=gr.Progress()):
11
+ """Process files and generate comprehensive report with progress tracking"""
12
+ progress(0, desc="Starting analysis...")
13
  full_content = []
14
 
15
+ # Read files with progress
16
+ for i, path in enumerate(file_paths):
17
+ progress(i/len(file_paths), f"Reading {path.split('/')[-1]}...")
18
  try:
19
  with open(path, 'r', encoding='utf-8') as f:
20
  content = f.read()
21
+ full_content.append(f"## {path.split('/')[-1]}\n{content}\n")
22
  except Exception as e:
23
  return f"Error processing {path}: {str(e)}"
24
+
25
+ # Generate report with progress
26
+ progress(0.8, "Analyzing content with AI...")
27
  report = agent.run(f"""
28
  Analyze these documents and create a detailed report:
29
 
30
+ {"".join(full_content)[:10000]}
31
 
32
+ Report structure:
33
+ 1. Executive Summary
34
+ 2. Key Findings
35
+ 3. Important Patterns
36
+ 4. Recommendations
37
 
38
+ Use professional markdown formatting with headings and bullet points.
39
  """)
40
 
41
+ progress(1.0, "Analysis complete!")
42
  return report
43
 
44
  with gr.Blocks() as demo:
45
+ gr.Markdown("# Professional Document Analyzer")
46
 
47
  with gr.Row():
48
+ with gr.Column(scale=1):
49
+ file_input = gr.File(
50
+ file_count="multiple",
51
+ file_types=[".txt"],
52
+ label="Upload Documents"
53
+ )
54
+ process_btn = gr.Button("Generate Report", variant="primary")
55
+ status = gr.Textbox(label="Processing Status", interactive=False)
56
+
57
+ with gr.Column(scale=2, variant="panel"):
58
+ gr.Markdown("## Analysis Report")
59
+ report_output = gr.Markdown(
60
+ elem_classes="report-box",
61
+ label="",
62
+ show_label=False
63
+ )
64
 
65
+ @process_btn.click(
 
66
  inputs=file_input,
67
+ outputs=[status, report_output]
68
  )
69
+ def process_files(files):
70
+ if not files:
71
+ return "No files uploaded", ""
72
+
73
+ file_paths = [f.name for f in files]
74
+
75
+ def update_progress(progress):
76
+ return lambda p: progress(p)
77
+
78
+ return (
79
+ gr.Progress().track() | # Progress indicator
80
+ analyze_content(file_paths)
81
+ )
82
 
83
  if __name__ == "__main__":
84
  demo.launch(