Skip to content

Add Simple GUI for Fuzzy Logic Experimentation and Code Generation #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 2, 2025

This PR implements a comprehensive web-based GUI for experimenting with fuzzy logic and generating Python code, addressing the need for an interactive tool to explore fuzzy logic concepts.

Features

Interactive Web Interface - Clean, intuitive GUI accessible via web browser
Domain Creation - Define fuzzy logic domains with custom ranges and resolution
Fuzzy Set Builder - Create fuzzy sets using various membership functions:

  • R (Rising): Sigmoid-like function that rises from 0 to 1
  • S (Falling): Sigmoid-like function that falls from 1 to 0
  • Triangular: Triangle-shaped membership function
  • Trapezoid: Trapezoid-shaped membership function
  • Rectangular: Rectangular/plateau membership function

Real-time Visualization - Interactive plotting of fuzzy sets using matplotlib
Value Testing - Test input values against fuzzy sets to see membership degrees
Code Generation - Automatically generate clean Python code that recreates your fuzzy logic setup

Usage

Command Line Interface

# Start the GUI
python -m fuzzylogic.gui.cli

# Custom port
python -m fuzzylogic.gui.cli --port 8080

Python API

import fuzzylogic

# Start the GUI (opens browser automatically)
fuzzylogic.run_gui()

Example Workflow

  1. Create Domain: Define a "temperature" domain (0-40°C)
  2. Add Fuzzy Sets: Create "cold" (S function), "warm" (triangular), "hot" (R function)
  3. Visualize: Plot all sets to see their shapes and overlaps
  4. Test Values: Input temperature values to see membership degrees
  5. Generate Code: Get Python code to use in your applications
# Generated code example:
from fuzzylogic.classes import Domain
from fuzzylogic.functions import R, S, triangular

temperature = Domain('temperature', 0, 40, res=0.1)
temperature.cold = S(0, 15)
temperature.warm = triangular(10, 30, c=20)
temperature.hot = R(25, 40)

# Test usage
result = temperature(22)  # {'cold': 0.0, 'warm': 0.8, 'hot': 0.0}

Implementation Details

  • Pure Python implementation using built-in http.server (no external web framework dependencies)
  • Matplotlib integration for server-side plot generation with base64 encoding
  • JSON API for frontend-backend communication
  • Comprehensive tests covering all GUI functionality
  • Backward compatibility - all existing library functionality remains unchanged

Files Added

  • src/fuzzylogic/gui/app.py - Main GUI application with web server
  • src/fuzzylogic/gui/cli.py - Command-line interface
  • src/fuzzylogic/gui/example.py - Temperature control system example
  • tests/test_gui.py - Comprehensive test suite for GUI functionality

Fuzzy Logic GUI Screenshot

The GUI makes fuzzy logic accessible to users who want to experiment interactively before writing code, while automatically generating production-ready Python code for their fuzzy logic systems.

Fixes #17.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Simple GUI to experiment and generate code Add Simple GUI for Fuzzy Logic Experimentation and Code Generation Jul 2, 2025
@Copilot Copilot AI requested a review from amogorkon July 2, 2025 13:14
Copilot finished work on behalf of amogorkon July 2, 2025 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simple GUI to experiment and generate code
2 participants