Skip to content

Commit

Permalink
chore: front end project
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Nov 15, 2024
1 parent 0dfccf7 commit 2794a9d
Show file tree
Hide file tree
Showing 22 changed files with 295 additions and 238 deletions.
2 changes: 1 addition & 1 deletion bindings/streamlit-gpt-vis/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
recursive-include streamlit_gpt_vis/frontend/build *
recursive-include streamlit_gpt_vis/frontend/dist *
19 changes: 16 additions & 3 deletions bindings/streamlit-gpt-vis/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# streamlit-gpt-vis

Components for GPTs, generative AI, and LLM projects. Not only UI Components.
[![Latest Stable Version](https://img.shields.io/pypi/v/streamlit-gpt-vis.svg)](https://pypi.python.org/pypi/streamlit-gpt-vis) [![Pypi Download](https://img.shields.io/pypi/dm/streamlit-gpt-vis)](https://pypi.python.org/pypi/streamlit-gpt-vis)

## Installation instructions
Streamlit binding for [`@AntV/GPT-Vis`](https://github.com/antvis/GPT-Vis) Components for GPTs, generative AI, and LLM projects. Not only UI Components.

## Installation

```sh
pip install streamlit-gpt-vis
```

## Usage instructions
## Usage

```python
import streamlit as st
Expand All @@ -27,3 +29,14 @@ Here’s a visualization of Haidilao's food delivery revenue from 2013 to 2022.

gpt_vis_renderer(content, config=None)
```

## API

### gpt_vis_renderer(content: str, config: dict = None)

- content: Markdown content
- config: GPT-Vis [ConfigProvider](https://github.com/antvis/GPT-Vis/blob/main/src/ConfigProvider/index.md) config

## License

[MIT](./LICENSE)
8 changes: 6 additions & 2 deletions bindings/streamlit-gpt-vis/example/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
```vis-chart
{ "type": "line","data": [{"time":2013,"value":59.3},{"time":2014,"value":64.4},{"time":2015,"value":68.9},{"time":2016,"value":74.4},{"time":2017,"value":82.7},{"time":2018,"value":91.9},{"time":2019,"value":99.1},{"time":2020,"value":101.6},{"time":2021,"value":114.4},{"time":2022,"value":121}] }
```
```
```vis-chart
{ "type":"network-graph","data":{"nodes":[{"name":"哈利·波特"},{"name":"赫敏·格兰杰"},{"name":"罗恩·韦斯莱"},{"name":"伏地魔"}],"edges":[{"source":"哈利·波特","target":"赫敏·格兰杰","name":"朋友"},{"source":"哈利·波特","target":"罗恩·韦斯莱","name":"朋友"},{"source":"哈利·波特","target":"伏地魔","name":"敌人"},{"source":"伏地魔","target":"哈利·波特","name":"试图杀死"}]} }
```
''')

st.markdown("---")
Expand All @@ -40,6 +44,6 @@
# it is considered a new instance and will be re-mounted on the frontend
# and lose its current state. In this case, we want to vary the component's
# "content" argument without having it get recreated.
content_input = st.text_input("Enter render content", value="# GPT-VIS \n\nComponents for GPTs, generative AI, and LLM projects. Not only UI Components.")
content_input = st.text_input("Enter render content", value="#### GPT-VIS \n\n Components for GPTs, generative AI, and LLM projects. Not only UI Components.")

gpt_vis_renderer(content_input, config={'plot': { 'theme': { 'type': 'academy' }}})
6 changes: 3 additions & 3 deletions bindings/streamlit-gpt-vis/streamlit_gpt_vis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# the component, and True when we're ready to package and distribute it.
# (This is, of course, optional - there are innumerable ways to manage your
# release process.)
_RELEASE = False
_RELEASE = True

# Declare a Streamlit component. `declare_component` returns a function
# that is used to create instances of the component. We're naming this
Expand All @@ -27,14 +27,14 @@
# Pass `url` here to tell Streamlit that the component will be served
# by the local dev server that you run via `npm run start`.
# (This is useful while your component is in development.)
url="http://localhost:3001",
url="http://localhost:5173",
)
else:
# When we're distributing a production version of the component, we'll
# replace the `url` param with `path`, and point it to the component's
# build directory:
parent_dir = os.path.dirname(os.path.abspath(__file__))
build_dir = os.path.join(parent_dir, "frontend/build")
build_dir = os.path.join(parent_dir, "frontend/dist")
_component_func = components.declare_component("gpt_vis_renderer", path=build_dir)


Expand Down
24 changes: 24 additions & 0 deletions bindings/streamlit-gpt-vis/streamlit_gpt_vis/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

This file was deleted.

50 changes: 50 additions & 0 deletions bindings/streamlit-gpt-vis/streamlit_gpt_vis/frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
});
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react';

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
});
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import js from '@eslint/js';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
},
},
);
16 changes: 16 additions & 0 deletions bindings/streamlit-gpt-vis/streamlit_gpt_vis/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html lang="en">
<head>
<title>Streamlit Component</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Streamlit Component" />
<link rel="stylesheet" href="/bootstrap.min.css" />
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
54 changes: 23 additions & 31 deletions bindings/streamlit-gpt-vis/streamlit_gpt_vis/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,34 @@
{
"name": "streamlit-gpt-vis",
"version": "0.1.0",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@antv/gpt-vis": "^0.1.0",
"antd": "^5.22.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"streamlit-component-lib": "^2.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
"react": "^18.3.1",
"react-dom": "^18.3.1",
"streamlit-component-lib": "^2.0.0",
"streamlit-component-lib-react-hooks": "^1.1.1"
},
"homepage": ".",
"devDependencies": {
"@types/node": "^12.0.0",
"@types/react": "^18",
"@types/react-dom": "^18",
"react-scripts": "^5.0.1",
"typescript": "^5.0.0"
"@eslint/js": "^9.13.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
"eslint": "^9.13.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.11.0",
"typescript": "~5.6.2",
"typescript-eslint": "^8.11.0",
"vite": "^5.4.10",
"vite-plugin-externals": "^0.6.2"
}
}

This file was deleted.

Loading

0 comments on commit 2794a9d

Please sign in to comment.