|  | 
|  | 1 | +# Fuzzy Logic GUI | 
|  | 2 | + | 
|  | 3 | +This directory contains a web-based GUI for experimenting with fuzzy logic and generating Python code. | 
|  | 4 | + | 
|  | 5 | +## Features | 
|  | 6 | + | 
|  | 7 | +- **Create Domains**: Define fuzzy logic domains with custom ranges and resolution | 
|  | 8 | +- **Add Fuzzy Sets**: Create fuzzy sets using various membership functions: | 
|  | 9 | +  - R (Rising): Sigmoid-like function that rises from 0 to 1 | 
|  | 10 | +  - S (Falling): Sigmoid-like function that falls from 1 to 0 | 
|  | 11 | +  - Triangular: Triangle-shaped membership function | 
|  | 12 | +  - Trapezoid: Trapezoid-shaped membership function   | 
|  | 13 | +  - Rectangular: Rectangular/plateau membership function | 
|  | 14 | +- **Visualization**: Plot domains and their fuzzy sets using matplotlib | 
|  | 15 | +- **Test Values**: Test input values against all sets in a domain | 
|  | 16 | +- **Code Generation**: Generate Python code that recreates your fuzzy logic setup | 
|  | 17 | + | 
|  | 18 | +## Usage | 
|  | 19 | + | 
|  | 20 | +### Command Line | 
|  | 21 | + | 
|  | 22 | +Start the GUI from the command line: | 
|  | 23 | + | 
|  | 24 | +```bash | 
|  | 25 | +# From the repository root | 
|  | 26 | +python -m fuzzylogic.gui.cli | 
|  | 27 | + | 
|  | 28 | +# Or with custom port | 
|  | 29 | +python -m fuzzylogic.gui.cli --port 8080 | 
|  | 30 | + | 
|  | 31 | +# Don't open browser automatically | 
|  | 32 | +python -m fuzzylogic.gui.cli --no-browser | 
|  | 33 | +``` | 
|  | 34 | + | 
|  | 35 | +### Python API | 
|  | 36 | + | 
|  | 37 | +Start the GUI programmatically: | 
|  | 38 | + | 
|  | 39 | +```python | 
|  | 40 | +import fuzzylogic | 
|  | 41 | + | 
|  | 42 | +# Start the GUI (will open browser automatically) | 
|  | 43 | +fuzzylogic.run_gui() | 
|  | 44 | + | 
|  | 45 | +# Or with custom port | 
|  | 46 | +fuzzylogic.run_gui(port=8080) | 
|  | 47 | +``` | 
|  | 48 | + | 
|  | 49 | +### Direct Module Usage | 
|  | 50 | + | 
|  | 51 | +```python | 
|  | 52 | +from fuzzylogic.gui.app import run_gui | 
|  | 53 | + | 
|  | 54 | +# Start the server | 
|  | 55 | +run_gui(port=8000) | 
|  | 56 | +``` | 
|  | 57 | + | 
|  | 58 | +## Example Workflow | 
|  | 59 | + | 
|  | 60 | +1. **Create a Domain**: Enter a name (e.g., "temperature"), set the range (0-40), and click "Create Domain" | 
|  | 61 | + | 
|  | 62 | +2. **Add Fuzzy Sets**:  | 
|  | 63 | +   - Select the domain from the dropdown | 
|  | 64 | +   - Enter a set name (e.g., "cold") | 
|  | 65 | +   - Choose function type (e.g., "S" for falling) | 
|  | 66 | +   - Set parameters (e.g., low=0, high=15) | 
|  | 67 | +   - Click "Add Set" | 
|  | 68 | + | 
|  | 69 | +3. **Visualize**: Select the domain and click "Plot Domain" to see a graph of all fuzzy sets | 
|  | 70 | + | 
|  | 71 | +4. **Test Values**: Enter a test value and see the membership degrees for each set | 
|  | 72 | + | 
|  | 73 | +5. **Generate Code**: Click "Generate Python Code" to get Python code that recreates your setup | 
|  | 74 | + | 
|  | 75 | +## Implementation Details | 
|  | 76 | + | 
|  | 77 | +The GUI is implemented as a simple HTTP server that serves a single-page web application. It uses: | 
|  | 78 | + | 
|  | 79 | +- Pure Python with built-in `http.server` (no external web framework dependencies) | 
|  | 80 | +- Matplotlib for plotting (with Agg backend for server-side rendering) | 
|  | 81 | +- HTML/CSS/JavaScript for the frontend | 
|  | 82 | +- JSON API for communication between frontend and backend | 
|  | 83 | + | 
|  | 84 | +## Files | 
|  | 85 | + | 
|  | 86 | +- `app.py`: Main GUI application with web server and fuzzy logic interface | 
|  | 87 | +- `cli.py`: Command-line interface for starting the GUI | 
|  | 88 | +- `__init__.py`: Module initialization | 
0 commit comments