File size: 1,914 Bytes
6a0ec6a
0604637
dbbcf50
91561ce
dbbcf50
6d4e0a3
e1e2089
6d4e0a3
 
 
0604637
 
 
 
a808dce
0604637
 
 
 
 
e3ecb0f
a6f506b
 
bb29d2e
e3ecb0f
0604637
 
bb29d2e
0604637
 
 
a6f506b
97d5125
bb29d2e
a808dce
97d5125
 
 
 
a6f506b
97d5125
a6f506b
 
0604637
 
f3a5662
6d4e0a3
97d5125
a808dce
 
97d5125
 
 
 
 
 
 
 
0604637
237bccb
db33f59
 
3df9eeb
db33f59
0604637
811c7ec
6a0ec6a
 
dbbcf50
 
 
0604637
dbbcf50
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import gradio as gr
import time
from smolagents import CodeAgent, HfApiModel

# Initialize the AI agent
agent = CodeAgent(
    tools=[],
    model=HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct"),
)

def analyze_content(file_paths):
    """Process files and generate report with status updates"""
    status = "Starting analysis..."
    yield "", status
    
    full_content = []
    for path in file_paths:
        status = f"Reading {path.split('/')[-1]}..."
        yield "", status
        
        try:
            with open(path, 'r', encoding='utf-8') as f:
                content = f.read()
                full_content.append(f"## {path.split('/')[-1]}\n{content}\n")
        except Exception as e:
            yield f"Error processing {path}: {str(e)}", ""
            return

    status = "Analyzing content with AI..."
    yield "", status
    
    report = agent.run(f"""
    Analyze these documents:
    {"".join(full_content)[:10000]}
    
    Create report with:
    1. Key insights
    2. Important patterns
    3. Actionable recommendations
    
    Use markdown formatting with headers.
    """)
    
    status = "Analysis complete!"
    yield report, status

with gr.Blocks() as demo:
    gr.Markdown("# Document Analysis System")
    
    with gr.Row():
        file_input = gr.File(
            file_count="multiple",
            file_types=[".txt"],
            label="Upload Documents"
        )
        process_btn = gr.Button("Generate Report", variant="primary")
    
    report_output = gr.Markdown(label="Analysis Report")
    status = gr.Textbox(label="Processing Status", interactive=False)

    process_btn.click(
        fn=analyze_content,
        inputs=file_input,
        outputs=[report_output, status],
        show_progress="hidden"
    )

if __name__ == "__main__":
    demo.launch(
        server_name="0.0.0.0",
        server_port=7860,
        share=True
    )