Spaces:
Build error
Build error
import gradio as gr | |
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 comprehensive report""" | |
full_content = [] | |
for path in file_paths: | |
try: | |
with open(path, 'r', encoding='utf-8') as f: | |
content = f.read() | |
full_content.append(f"--- {path.split('/')[-1]} ---\n{content}") | |
except Exception as e: | |
return f"Error processing {path}: {str(e)}" | |
report = agent.run(f""" | |
Analyze these documents and create a detailed report: | |
{''.join(full_content)[:10000]} # First 10k characters | |
Report should include: | |
1. Key themes and patterns | |
2. Important relationships | |
3. Contextual insights | |
4. Actionable recommendations | |
Use professional markdown formatting with headings. | |
""") | |
return report | |
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") | |
process_btn.click( | |
fn=analyze_content, | |
inputs=file_input, | |
outputs=report_output | |
) | |
if __name__ == "__main__": | |
demo.launch( | |
server_name="0.0.0.0", | |
server_port=7860, | |
share=True | |
) |