Spaces:
Sleeping
Sleeping
A newer version of the Streamlit SDK is available: 1.56.0
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
- Start the app
- Select a model (sidebar)
- Input text or use examples
- Ask questions
- View agent reasoning process
Examples
Question: "What is the sentiment and main topics?"
Agent Process:
- Thought: Need sentiment analysis
- Action: sentiment_analyzer
- Thought: Need keywords
- Action: keyword_extractor
- Final Answer: Combines results
Testing
python tests/test_tools.py
Deployment
Hugging Face Spaces
This project is ready for deployment to Hugging Face Spaces:
- Create Space: Go to huggingface.co/spaces and create a new Space with Streamlit SDK
- Upload Code: Push this repository or upload files via web UI
- Configure Secrets (Settings β Repository secrets):
OPENAI_API_KEY(required)LANGCHAIN_API_KEY(optional, for LangSmith tracing)LANGCHAIN_TRACING_V2(optional, set totruefor tracing)LANGCHAIN_PROJECT(optional, default:react-text-analyzer)
- Deploy: Space will automatically build and run
See SETUP.md for detailed instructions.
License
MIT License