S-Dreamer commited on
Commit
c99746f
·
verified ·
1 Parent(s): 25afd80

Upload 19 files

Browse files
.env ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+
2
+ # Add your Google API key here
3
+ GOOGLE_API_KEY=your_api_key_here
.flake8 ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+
2
+ [flake8]
3
+ max-line-length = 88
4
+ extend-ignore = E203, W503
5
+ exclude = .git,__pycache__,build,dist
6
+ per-file-ignores =
7
+ __init__.py:F401
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ Gemini_Generated_Image_j0j4pcj0j4pcj0j4.jfif filter=lfs diff=lfs merge=lfs -text
37
+ generated-icon.png filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
.pre-commit-config.yaml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ repos:
3
+ - repo: https://github.com/pre-commit/pre-commit-hooks
4
+ rev: v4.4.0
5
+ hooks:
6
+ - id: trailing-whitespace
7
+ - id: end-of-file-fixer
8
+ - id: check-yaml
9
+ - id: check-added-large-files
10
+
11
+ - repo: https://github.com/psf/black
12
+ rev: 23.7.0
13
+ hooks:
14
+ - id: black
15
+
16
+ - repo: https://github.com/PyCQA/isort
17
+ rev: 5.12.0
18
+ hooks:
19
+ - id: isort
20
+
21
+ - repo: https://github.com/PyCQA/flake8
22
+ rev: 6.1.0
23
+ hooks:
24
+ - id: flake8
25
+
26
+ - repo: https://github.com/pre-commit/mirrors-mypy
27
+ rev: v1.5.1
28
+ hooks:
29
+ - id: mypy
30
+ additional_dependencies: [types-all]
.replit ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ entrypoint = "main.py"
2
+ modules = ["python-3.11"]
3
+
4
+ [nix]
5
+ channel = "stable-24_05"
6
+
7
+ [unitTest]
8
+ language = "python3"
9
+
10
+ [gitHubImport]
11
+ requiredFiles = [".replit", "replit.nix"]
12
+
13
+ [deployment]
14
+ run = ["sh", "-c", "streamlit run main.py --server.address=0.0.0.0 --server.port=8080 --server.enableCORS=false --server.enableWebsocketCompression=false --server.headless=true"]
15
+ deploymentTarget = "cloudrun"
16
+
17
+ [[ports]]
18
+ localPort = 8080
19
+ externalPort = 8080
20
+
21
+ [[ports]]
22
+ localPort = 8501
23
+ externalPort = 80
24
+
25
+ [workflows]
26
+ runButton = "Run Streamlit"
27
+
28
+ [[workflows.workflow]]
29
+ name = "Run Streamlit"
30
+ author = 25868489
31
+
32
+ [[workflows.workflow.tasks]]
33
+ task = "shell.exec"
34
+ args = "streamlit run app.py --server.address=0.0.0.0 --server.port=8080 --server.headless=true --server.enableWebsocketCompression=false"
Gemini_Generated_Image_j0j4pcj0j4pcj0j4.jfif ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2f557cfd6b7e8d526b0047bc9736d5fb8e941b646d9992061f2e0127f1d9fcbc
3
+ size 328326
LICENSE.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2025 WhacktheJacker aka Canstralian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,14 +1,81 @@
1
  ---
2
- title: EnsembleAppBuilder
3
- emoji: 👁
4
- colorFrom: red
5
- colorTo: blue
6
  sdk: streamlit
7
- sdk_version: 1.43.2
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
- short_description: A Multi-Model App Builder Built On Streamlit
 
 
 
 
12
  ---
 
13
 
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Ensemble Model App Builder
3
+ emoji: 👀
4
+ colorFrom: purple
5
+ colorTo: gray
6
  sdk: streamlit
7
+ sdk_version: 1.42.2
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
+ short_description: An AI-powered App Builder for Streamlit and Gradio Apps
12
+ models:
13
+ - gemini-pro-2.0
14
+ - Salesforce/codet5-small
15
+ - bigscience/T0_3B
16
  ---
17
+ # Multi-Model App Builder
18
 
19
+ [![Hugging Face Spaces - SDK](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces%20SDK-blue)](https://huggingface.co/spaces/whackthejacker/ensemble-model-app-builder)
20
+ [![Streamlit App](https://img.shields.io/badge/Streamlit-App-orange.svg)](https://streamlit.io/)
21
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
22
+ [![Models: Gemini Pro 2.0, CodeT5-small, T0_3B](https://img.shields.io/badge/Models-Gemini%20Pro%202.0%2C%20CodeT5--small%2C%20T0_3B-green)](https://huggingface.co/whackthejacker/ensemble-model-app-builder)
23
+
24
+ 👀 **Enhanced Multi-Model AI-Powered App Builder for Streamlit and Gradio Applications**
25
+
26
+ Discover a more intuitive and seamless way to create Streamlit and Gradio applications with our Hugging Face Space. Harness the combined prowess of several large language models, letting you develop interactive web tools swiftly and with minimal coding experience.
27
+
28
+ ## Overview
29
+
30
+ Leverage this tool to automatically generate Python code tailored for either Streamlit or Gradio apps. Our system integrates the capabilities of the Gemini Pro 2.0, Salesforce/codet5-small, and bigscience/T0_3B models to craft your code. Begin by picking a predefined task or entering a custom directive.
31
+
32
+ Originally conceptualized by:
33
+ **Louie F. Cervantes, M.Eng (Information Engineering)**
34
+ West Visayas State University
35
+ This iteration, refined and expanded by **WhackTheJacker**, maximizes the utility of multiple models to boost code generation accuracy and variety.
36
+
37
+ ## Key Features
38
+
39
+ * **Advanced Multi-Model Code Generation:** Utilizes Gemini Pro 2.0, Salesforce/codet5-small, and bigscience/T0_3B for enhanced and reliable code synthesis.
40
+ * **User-Friendly Interface:** Simply describe your desired application functionality, and let the AI handle the rest.
41
+ * **Support for Streamlit and Gradio:** Opt for the framework that best suits your requirements.
42
+ * **Efficient Prototyping:** Condense your development timeline with rapid code generation and iterative features.
43
+
44
+ ## Step-by-Step Guide
45
+
46
+ 1. **App Description:** Provide a clear and concise outline of the application you wish to construct.
47
+ 2. **Framework Selection:** Decide whether to generate a Streamlit or Gradio application.
48
+ 3. **Initiate Code Generation:** Press the "Generate" button and watch the AI draft your Python script.
49
+ 4. **Customize and Validate:** Examine the code output and adjust as required.
50
+ 5. **Deployment or Execution:** Run the code on a local setup or deploy using services like Streamlit Sharing or Hugging Face Spaces.
51
+
52
+ ## Model Summary
53
+
54
+ - **Gemini Pro 2.0:** Offers extensive code generation and adept natural language interpretation.
55
+ - **Salesforce/codet5-small:** Specializes in refining code and enhancing output quality.
56
+ - **bigscience/T0_3B:** Excels in understanding natural language commands and execution.
57
+
58
+ ## Sample Scenario
59
+ "Devise a Streamlit app that accepts user input and showcases the input transformed into uppercase letters."
60
+
61
+ ## Setting Up Locally
62
+ 1. Clone the repository to your local machine.
63
+ 2. Install dependencies with: `pip install streamlit gradio transformers`
64
+ 3. Start the application: `streamlit run app.py`
65
+
66
+ ## Open Source Contribution
67
+ We welcome contributions! Encountered a bug or have enhancement ideas? Feel free to open an issue or contribute via pull request.
68
+
69
+ ## Licensing
70
+ This software is distributed under the Apache 2.0 License.
71
+
72
+ ## Special Thanks
73
+ * To Hugging Face for the Spaces platform and Transformers library.
74
+ * Google, for developing Gemini Pro.
75
+ * Salesforce, for the innovative CodeT5.
76
+ * BigScience for their contribution of T0.
77
+ * The dedicated communities behind Streamlit and Gradio.
78
+ * Louie F. Cervantes, M.Eng, for laying the project groundwork.
79
+
80
+ ## Reach Out
81
+ For any questions or feedback, don't hesitate to contact us.
app.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+
4
+ import google.generativeai as genai
5
+ import streamlit as st
6
+ from dotenv import load_dotenv
7
+
8
+ from ui.streamlit_ui import (
9
+ load_css,
10
+ render_code_display,
11
+ render_footer,
12
+ render_framework_selector,
13
+ render_generate_button,
14
+ render_header,
15
+ render_task_selector,
16
+ )
17
+
18
+ # Initialize session state
19
+ if "api_key" not in st.session_state:
20
+ st.session_state["api_key"] = None
21
+ if "generated_code" not in st.session_state:
22
+ st.session_state["generated_code"] = None
23
+ if "selected_framework" not in st.session_state:
24
+ st.session_state["selected_framework"] = None
25
+
26
+ def with_retry(func, max_retries=3, delay=1):
27
+ for attempt in range(max_retries):
28
+ try:
29
+ return func()
30
+ except Exception as e:
31
+ if attempt == max_retries - 1:
32
+ raise e
33
+ time.sleep(delay)
34
+
35
+ # Set page configuration
36
+ st.set_page_config(
37
+ page_title="Multi-Model App Builder",
38
+ page_icon="🛠️",
39
+ layout="wide",
40
+ initial_sidebar_state="expanded",
41
+ )
42
+
43
+ # Load custom CSS
44
+ load_css()
45
+
46
+ # Load environment variables
47
+ load_dotenv()
48
+
49
+ # Configure Google Generative AI
50
+ api_key = os.getenv("GOOGLE_API_KEY")
51
+ if api_key and api_key != "your_api_key_here":
52
+ try:
53
+ with st.spinner("Configuring API connection..."):
54
+ with_retry(lambda: genai.configure(api_key=api_key))
55
+ st.session_state["api_key"] = api_key
56
+ st.success("Google API key configured successfully!")
57
+ except Exception as e:
58
+ st.error(f"Error configuring Google API key: {e}")
59
+ st.info("The app will continue to run with limited functionality.")
60
+ else:
61
+ st.sidebar.warning(
62
+ "Google API key not configured. Please add your API key to the .env file as GOOGLE_API_KEY."
63
+ )
64
+ st.sidebar.info("You can get a Google API key from https://ai.google.dev/")
65
+ api_key_input = st.sidebar.text_input(
66
+ "Or enter your Google API key here:", type="password"
67
+ )
68
+ if api_key_input:
69
+ try:
70
+ with st.spinner("Configuring API connection..."):
71
+ with_retry(lambda: genai.configure(api_key=api_key_input))
72
+ st.session_state["api_key"] = api_key_input
73
+ st.success("Google API key configured successfully!")
74
+ except Exception as e:
75
+ st.error(f"Error configuring Google API key: {e}")
76
+ st.session_state["api_key"] = None
77
+
78
+ def generate_app_code(framework, task):
79
+ if not st.session_state.get("api_key"):
80
+ return "API key not configured. Please provide a Google API key to generate code."
81
+
82
+ try:
83
+ prompt = (
84
+ f"Create a {framework} app for the following task: {task}. "
85
+ "Provide the full Python code and ensure it is functional."
86
+ )
87
+
88
+ def get_response():
89
+ model = genai.GenerativeModel("gemini-1.5-flash")
90
+ return model.generate_content(prompt)
91
+
92
+ response = with_retry(get_response)
93
+ if hasattr(response, "text"):
94
+ return response.text
95
+ return "Error: Unable to generate code. Invalid response format."
96
+ except Exception as e:
97
+ return f"An error occurred: {e}"
98
+
99
+ def main():
100
+ render_header()
101
+
102
+ col1, col2 = st.columns([2, 1])
103
+
104
+ with col1:
105
+ framework = render_framework_selector()
106
+ st.session_state["selected_framework"] = framework
107
+ task = render_task_selector()
108
+
109
+ if render_generate_button():
110
+ with st.spinner("Generating code with AI..."):
111
+ app_code = generate_app_code(framework, task)
112
+ if app_code:
113
+ st.session_state["generated_code"] = app_code
114
+ st.success("Code generated successfully!")
115
+ else:
116
+ st.error("Failed to generate the app code. Please try again.")
117
+
118
+ with col2:
119
+ st.markdown("### App Preview")
120
+ st.info(
121
+ f"Framework: {st.session_state['selected_framework'] if st.session_state['selected_framework'] else 'Not selected'}"
122
+ )
123
+ st.markdown("### Sample Apps")
124
+ st.image(
125
+ "https://streamlit.io/images/brand/streamlit-logo-secondary-colormark-darktext.png",
126
+ width=200,
127
+ )
128
+ st.image("https://gradio.app/images/logo.svg", width=200)
129
+
130
+ st.markdown("### Tips")
131
+ st.info(
132
+ "• Be specific in your task description\n• Run the generated code in a new file\n• Experiment with different frameworks"
133
+ )
134
+
135
+ if st.session_state["generated_code"]:
136
+ render_code_display(st.session_state["generated_code"])
137
+
138
+ render_footer()
139
+
140
+ if __name__ == "__main__":
141
+ try:
142
+ main()
143
+ except Exception as e:
144
+ st.error(f"An error occurred: {str(e)}")
conversation.md ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## import streamlit as stimport google.generativeai as genaiimport osAPI_KEY = os.getenv("GEMINI_API_KEY")genai.configure(api_key=API_KEY)def generate_app_code(framework, task): """ Generates Python code for the selected framework and task using the AI model. Args: framework (str): The selected framework ('Streamlit' or 'Gradio'). task (str): The task for which the app will be generated. Returns: str: Generated Python code or an error message. """ try: # Construct the prompt prompt = ( f"Create a {framework} app for the following task: {task}. " "Provide the full Python code and ensure it is functional." ) # Send the prompt to the model model = genai.GenerativeModel("gemini-1.5-flash") response = model.generate_content(prompt) return response.text except Exception as e: return f"An error occurred: {e}"def main(): # Streamlit UI st.title("App Builder: Streamlit or Gradio") with st.expander("ℹ️ About"): st.write( "This tool generates Python code for a Streamlit or Gradio app based on a selected task. " "It uses the Gemini 1.5 flash model to generate the code. " "You can select a predefined task or enter a custom one.") st.markdown("Programmed by: \n\n \ Louie F. Cervantes, M.Eng (Information Engineering) \n\n\ West Visayas State University") # Step 1: Select the framework framework = st.selectbox("Select a framework:", ["Streamlit", "Gradio"]) # Step 2: Select a task or enter a custom one predefined_tasks = [ "Interactive Data Explorer", "Simple Linear Regression", "Image Classification with Pre-trained Model", "Text Summarizer", "Sentiment Analysis Tool", "Interactive Quiz App", "Basic Calculator", "Unit Converter", "Color Mixer", "Simple Game (e.g., Number Guessing)" ] task = st.selectbox("Select a predefined task:", predefined_tasks) custom_task = st.text_input("Or enter a custom task:") # Use the custom task if provided task = custom_task if custom_task.strip() else task # Step 3: Generate the app code if st.button("Generate App Code"): with st.spinner("Generating code..."): app_code = generate_app_code(framework, task) if app_code: st.subheader("Generated Code") st.code(app_code, language="python") else: st.error("Failed to generate the app code. Please try again.")if __name__ == "__main__": main()
2
+
3
+ ```python
4
+ import streamlit as st
5
+ import google.generativeai as genai
6
+ import os
7
+
8
+ API_KEY = os.getenv("GEMINI_API_KEY")
9
+ genai.configure(api_key=API_KEY)
10
+
11
+ def generate_app_code(framework, task):
12
+ """
13
+ Generates Python code for the selected framework and task using the AI model.
14
+ Args:
15
+ framework (str): The selected framework ('Streamlit' or 'Gradio').
16
+ task (str): The task for which the app will be generated.
17
+ Returns:
18
+ str: Generated Python code or an error message.
19
+ """
20
+ try:
21
+ # Construct the prompt
22
+ prompt = (
23
+ f"Create a {framework} app for the following task: {task}. "
24
+ "Provide the full Python code and ensure it is functional."
25
+ )
26
+ # Send the prompt to the model
27
+ model = genai.GenerativeModel("gemini-1.5-flash")
28
+ response = model.generate_content(prompt)
29
+ return response.text
30
+ except Exception as e:
31
+ return f"An error occurred: {e}"
32
+
33
+ def main():
34
+ # Streamlit UI
35
+ st.title("Multi-Model App Builder")
36
+
37
+ with st.expander("ℹ️ About"):
38
+ st.write(
39
+ "This tool generates Python code for a Streamlit or Gradio app based on a selected task. "
40
+ "It uses the Gemini 1.5 flash model to generate the code. "
41
+ "You can select a predefined task or enter a custom one."
42
+ )
43
+ st.write("This project is based on the initial work of:")
44
+ st.markdown(
45
+ "Louie F. Cervantes, M.Eng (Information Engineering) \n\n"
46
+ "West Visayas State University"
47
+ )
48
+ st.write("This version has been created and expanded upon by **WhackTheJacker** to utilize multiple models for enhanced code generation.")
49
+
50
+ # Step 1: Select the framework
51
+ framework = st.selectbox("Select a framework:", ["Streamlit", "Gradio"])
52
+
53
+ # Step 2: Select a task or enter a custom one
54
+ predefined_tasks = [
55
+ "Interactive Data Explorer",
56
+ "Simple Linear Regression",
57
+ "Image Classification with Pre-trained Model",
58
+ "Text Summarizer",
59
+ "Sentiment Analysis Tool",
60
+ "Interactive Quiz App",
61
+ "Basic Calculator",
62
+ "Unit Converter",
63
+ "Color Mixer",
64
+ "Simple Game (e.g., Number Guessing)",
65
+ ]
66
+ task = st.selectbox("Select a predefined task:", predefined_tasks)
67
+ custom_task = st.text_input("Or enter a custom task:")
68
+ # Use the custom task if provided
69
+ task = custom_task if custom_task.strip() else task
70
+
71
+ # Step 3: Generate the app code
72
+ if st.button("Generate App Code"):
73
+ with st.spinner("Generating code..."):
74
+ app_code = generate_app_code(framework, task)
75
+ if app_code:
76
+ st.subheader("Generated Code")
77
+ st.code(app_code, language="python")
78
+ else:
79
+ st.error("Failed to generate the app code. Please try again.")
80
+
81
+ st.markdown("""
82
+ ## Acknowledgements
83
+
84
+ * Hugging Face for providing the Spaces platform and Transformers library.
85
+ * Google for Gemini Pro.
86
+ * Salesforce for CodeT5.
87
+ * BigScience for T0.
88
+ * Streamlit and Gradio communities.
89
+ * Louie F. Cervantes, M.Eng for the foundational work.
90
+ """)
91
+
92
+ if __name__ == "__main__":
93
+ main()
94
+ ```
95
+
96
+ **Changes Made:**
97
+
98
+ 1. **Title Update:**
99
+ * `st.title("App Builder: Streamlit or Gradio")` changed to `st.title("Multi-Model App Builder")`
100
+ 2. **About Section Modification:**
101
+ * The `st.expander("ℹ️ About")` section now includes the acknowledgment of Louie F. Cervantes's work and WhackTheJacker's adaptation.
102
+ * Specifically, I added `st.write("This project is based on the initial work of:")` and `st.write("This version has been created and expanded upon by **WhackTheJacker** to utilize multiple models for enhanced code generation.")`
103
+ 3. **Acknowledgements Section Addition:**
104
+ * Added an `st.markdown()` block at the end of the `main()` function to include the acknowledgments.
105
+ 4. **Formatting:**
106
+ * Improved the formatting of the markdown for better readability.
107
+ * Used `st.write()` for simple text and `st.markdown()` for formatted text, including line breaks.
108
+ 5. **Model Update:**
109
+ * Please note that the code still only uses the gemini-1.5-flash model. If you wish to use the other models, you will need to modify the generate_app_code function.
generated-icon.png ADDED

Git LFS Details

  • SHA256: 1beab1f98d445927a3963f3944ffcb7a5c34aab5228e63b8e00abc956d0ec4ec
  • Pointer size: 131 Bytes
  • Size of remote file: 163 kB
gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
gitignore ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # PyPI configuration file
171
+ .pypirc
172
+
pyproject.toml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "python-template"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = ["Your Name <you@example.com>"]
6
+ requires-python = ">=3.11"
7
+ dependencies = []
python-tests.yml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Python application
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - name: Set up Python version
12
+ uses: actions/setup-python@v2
13
+ with:
14
+ python-version: '3.11'
15
+
16
+ - name: Install dependencies
17
+ run: |
18
+ python -m pip install --upgrade pip
19
+ pip install -r requirements.txt
20
+
21
+ - name: Run tests
22
+ run: |
23
+ pytest tests/
replit.nix ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {pkgs}: {
2
+ deps = [
3
+ pkgs.glibcLocales
4
+ pkgs.ffmpeg-full
5
+ pkgs.black
6
+ ];
7
+ }
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ streamlit==1.37.0
3
+ google-generativeai==0.3.0
4
+ python-dotenv==1.0.0
5
+ gradio==5.20.0
6
+ flake8==6.1.0
7
+ pytest==7.4.0
8
+ pytest-mock==3.11.1
9
+ autopep8
10
+ isort
11
+ mypy
12
+ pylint
setup.cfg ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ [pylint]
3
+ max-line-length = 88
4
+ disable = C0111,R0903,C0103
5
+ good-names = i,j,k,ex,Run,_,id
6
+ ignore = CVS,tests
7
+
8
+ [mypy]
9
+ python_version = 3.11
10
+ disallow_untyped_defs = True
11
+ ignore_missing_imports = True
12
+ check_untyped_defs = True
13
+ warn_redundant_casts = True
14
+ warn_unused_ignores = True
15
+ warn_return_any = True
16
+ strict_optional = True
17
+
18
+ [isort]
19
+ profile = black
20
+ multi_line_output = 3
21
+ include_trailing_comma = True
22
+ force_grid_wrap = 0
23
+ use_parentheses = True
24
+ ensure_newline_before_comments = True
25
+ line_length = 88
uv.lock ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ version = 1
2
+ requires-python = ">=3.11"
3
+
4
+ [[package]]
5
+ name = "python-template"
6
+ version = "0.1.0"
7
+ source = { virtual = "." }