ReAct-Text-Analyzer / README.md
Easonwangzk's picture
Initial commit
a01e687

A newer version of the Streamlit SDK is available: 1.56.0

Upgrade
metadata
title: ReAct Text Analyzer
emoji: πŸ€–
colorFrom: blue
colorTo: green
sdk: streamlit
sdk_version: 1.28.0
app_file: app.py
pinned: false

ReAct Text Analyzer

A Streamlit application using the ReAct (Reasoning + Acting) framework with OpenAI GPT for intelligent text analysis.

Features

  • Word Counter: Total words, unique words, and top frequent words
  • Keyword Extractor: TF-IDF based keyword extraction
  • Sentiment Analyzer: Dictionary-based sentiment analysis
  • ReAct Agent: Intelligent reasoning and tool selection

Quick Start

1. Setup Environment

# Copy and edit .env file
cp .env.example .env
nano .env  # Add your OpenAI API key

2. Install Dependencies

pip install -r requirements.txt

3. Run Application

# Option 1: Use script
./run.sh

# Option 2: Manual
cd src
streamlit run app.py

Project Structure

Assignment-Research/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ agent/
β”‚   β”‚   β”œβ”€β”€ react_agent.py    # ReAct agent implementation
β”‚   β”‚   └── prompts.py         # Prompt templates
β”‚   β”œβ”€β”€ tools/
β”‚   β”‚   β”œβ”€β”€ word_counter.py
β”‚   β”‚   β”œβ”€β”€ keyword_extractor.py
β”‚   β”‚   └── sentiment_analyzer.py
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   └── config.py          # Configuration
β”‚   └── app.py                 # Streamlit app
β”œβ”€β”€ tests/
β”‚   └── test_tools.py
β”œβ”€β”€ .env                       # Your API keys (not tracked)
β”œβ”€β”€ .env.example              # Template
β”œβ”€β”€ requirements.txt
└── run.sh                    # Quick start script

Configuration

Edit .env file:

# Required
OPENAI_API_KEY=sk-your-key-here

# Optional
MODEL_NAME=gpt-4-turbo-preview
LANGCHAIN_TRACING_V2=false

Usage

  1. Start the app
  2. Select a model (sidebar)
  3. Input text or use examples
  4. Ask questions
  5. View agent reasoning process

Examples

Question: "What is the sentiment and main topics?"

Agent Process:

  1. Thought: Need sentiment analysis
  2. Action: sentiment_analyzer
  3. Thought: Need keywords
  4. Action: keyword_extractor
  5. Final Answer: Combines results

Testing

python tests/test_tools.py

Deployment

Hugging Face Spaces

This project is ready for deployment to Hugging Face Spaces:

  1. Create Space: Go to huggingface.co/spaces and create a new Space with Streamlit SDK
  2. Upload Code: Push this repository or upload files via web UI
  3. Configure Secrets (Settings β†’ Repository secrets):
    • OPENAI_API_KEY (required)
    • LANGCHAIN_API_KEY (optional, for LangSmith tracing)
    • LANGCHAIN_TRACING_V2 (optional, set to true for tracing)
    • LANGCHAIN_PROJECT (optional, default: react-text-analyzer)
  4. Deploy: Space will automatically build and run

See SETUP.md for detailed instructions.

License

MIT License