Spaces:
Running
Running
Commit
·
67b94be
0
Parent(s):
Add .gitignore, README, app.py, and requirements.txt for project setup
Browse files- .gitignore +123 -0
- README.md +45 -0
- app.py +60 -0
- requirements.txt +79 -0
.gitignore
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
env/
|
12 |
+
venv/
|
13 |
+
ENV/
|
14 |
+
build/
|
15 |
+
develop-eggs/
|
16 |
+
dist/
|
17 |
+
downloads/
|
18 |
+
eggs/
|
19 |
+
.eggs/
|
20 |
+
lib/
|
21 |
+
lib64/
|
22 |
+
parts/
|
23 |
+
sdist/
|
24 |
+
var/
|
25 |
+
wheels/
|
26 |
+
share/python-wheels/
|
27 |
+
*.egg-info/
|
28 |
+
.installed.cfg
|
29 |
+
*.egg
|
30 |
+
MANIFEST
|
31 |
+
|
32 |
+
# PyInstaller
|
33 |
+
# Usually these files are written by a python script from a template
|
34 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
35 |
+
*.manifest
|
36 |
+
*.spec
|
37 |
+
|
38 |
+
# Installer logs
|
39 |
+
pip-log.txt
|
40 |
+
pip-delete-this-directory.txt
|
41 |
+
|
42 |
+
# Unit test / coverage reports
|
43 |
+
htmlcov/
|
44 |
+
.tox/
|
45 |
+
.nox/
|
46 |
+
.coverage
|
47 |
+
.coverage.*
|
48 |
+
.cache
|
49 |
+
nosetests.xml
|
50 |
+
coverage.xml
|
51 |
+
*.cover
|
52 |
+
*.py,cover
|
53 |
+
.hypothesis/
|
54 |
+
.pytest_cache/
|
55 |
+
cover/
|
56 |
+
|
57 |
+
# Translations
|
58 |
+
*.mo
|
59 |
+
*.pot
|
60 |
+
|
61 |
+
# Django stuff:
|
62 |
+
*.log
|
63 |
+
local_settings.py
|
64 |
+
db.sqlite3
|
65 |
+
db.sqlite3-journal
|
66 |
+
|
67 |
+
# Flask stuff:
|
68 |
+
instance/
|
69 |
+
.webassets-cache
|
70 |
+
|
71 |
+
# Scrapy stuff:
|
72 |
+
.scrapy
|
73 |
+
|
74 |
+
# Sphinx documentation
|
75 |
+
docs/_build/
|
76 |
+
docs/_static/
|
77 |
+
|
78 |
+
# PyBuilder
|
79 |
+
target/
|
80 |
+
|
81 |
+
# Jupyter Notebook
|
82 |
+
.ipynb_checkpoints
|
83 |
+
|
84 |
+
# IPython
|
85 |
+
profile_default/
|
86 |
+
ipython_config.py
|
87 |
+
|
88 |
+
# pyenv
|
89 |
+
.python-version
|
90 |
+
|
91 |
+
# celery beat schedule file
|
92 |
+
celerybeat-schedule
|
93 |
+
|
94 |
+
# dotenv
|
95 |
+
.env
|
96 |
+
|
97 |
+
# virtualenv
|
98 |
+
.venv
|
99 |
+
venv/
|
100 |
+
ENV/
|
101 |
+
env.bak/
|
102 |
+
venv.bak/
|
103 |
+
|
104 |
+
# Spyder project settings
|
105 |
+
.spyderproject
|
106 |
+
.spyderworkspace
|
107 |
+
|
108 |
+
# Rope project settings
|
109 |
+
.ropeproject
|
110 |
+
|
111 |
+
# mkdocs documentation
|
112 |
+
/site
|
113 |
+
|
114 |
+
# mypy
|
115 |
+
.mypy_cache/
|
116 |
+
.dmypy.json
|
117 |
+
dmypy.json
|
118 |
+
|
119 |
+
# Pyre type checker
|
120 |
+
.pyre/
|
121 |
+
|
122 |
+
|
123 |
+
.gradio
|
README.md
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SmolAgents Project
|
2 |
+
|
3 |
+
## Introduction
|
4 |
+
|
5 |
+
This project is designed to...
|
6 |
+
|
7 |
+
## Prerequisites
|
8 |
+
|
9 |
+
- Python 3.x
|
10 |
+
- pip
|
11 |
+
|
12 |
+
## Setup
|
13 |
+
|
14 |
+
1. Clone the repository:
|
15 |
+
|
16 |
+
```sh
|
17 |
+
git clone https://github.com/yourusername/smolagents.git
|
18 |
+
cd smolagents
|
19 |
+
```
|
20 |
+
|
21 |
+
2. Create a virtual environment:
|
22 |
+
|
23 |
+
```sh
|
24 |
+
python3 -m venv venv
|
25 |
+
source venv/bin/activate # On Windows use `venv\Scripts\activate`
|
26 |
+
```
|
27 |
+
|
28 |
+
3. Install the dependencies:
|
29 |
+
|
30 |
+
```sh
|
31 |
+
pip install -r requirements.txt
|
32 |
+
```
|
33 |
+
|
34 |
+
4. Run the project:
|
35 |
+
```sh
|
36 |
+
python main.py
|
37 |
+
```
|
38 |
+
|
39 |
+
## Contributing
|
40 |
+
|
41 |
+
Please read `CONTRIBUTING.md` for details on our code of conduct, and the process for submitting pull requests.
|
42 |
+
|
43 |
+
## License
|
44 |
+
|
45 |
+
This project is licensed under the MIT License - see the `LICENSE` file for details.
|
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents import CodeAgent, HfApiModel, Tool
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Setup image generation tool
|
5 |
+
image_generation_tool = Tool.from_space(
|
6 |
+
"black-forest-labs/FLUX.1-schnell",
|
7 |
+
name="image_generator",
|
8 |
+
description="Generate an image from a prompt"
|
9 |
+
)
|
10 |
+
agent = CodeAgent(tools=[image_generation_tool], model=HfApiModel())
|
11 |
+
|
12 |
+
def generate_image(prompt):
|
13 |
+
try:
|
14 |
+
# 1) First, ask the agent to improve the prompt.
|
15 |
+
# We'll do only the 'improve' part here.
|
16 |
+
improved_prompt_result = agent.run(
|
17 |
+
f"Improve this prompt: {prompt}",
|
18 |
+
additional_args={
|
19 |
+
'user_prompt': prompt,
|
20 |
+
'output': 'improved_prompt'
|
21 |
+
}
|
22 |
+
)
|
23 |
+
# Convert the result to string
|
24 |
+
improved_prompt = str(improved_prompt_result).strip()
|
25 |
+
|
26 |
+
# 2) Now, use the improved prompt to generate the image
|
27 |
+
image_result = agent.run(
|
28 |
+
f"Generate an image from this improved prompt: {improved_prompt}",
|
29 |
+
additional_args={'user_prompt': improved_prompt}
|
30 |
+
)
|
31 |
+
generated_image = str(image_result)
|
32 |
+
|
33 |
+
# Return the image along with the improved prompt
|
34 |
+
return generated_image, improved_prompt
|
35 |
+
|
36 |
+
except Exception as e:
|
37 |
+
return None, f"Error: {str(e)}"
|
38 |
+
|
39 |
+
|
40 |
+
# Create Gradio interface
|
41 |
+
interface = gr.Interface(
|
42 |
+
fn=generate_image,
|
43 |
+
inputs=gr.Textbox(label="Enter your image prompt"),
|
44 |
+
outputs=[
|
45 |
+
gr.Image(label="Generated Image"),
|
46 |
+
gr.Textbox(label="Improved Prompt Used")
|
47 |
+
],
|
48 |
+
title="AI Image Generator",
|
49 |
+
description="Enter a prompt to generate an image using FLUX.1-schnell model (the prompt will be improved automatically).",
|
50 |
+
examples=[
|
51 |
+
["a cat wearing a cape"],
|
52 |
+
["cyberpunk city at night with neon lights"]
|
53 |
+
],
|
54 |
+
allow_flagging="auto",
|
55 |
+
flagging_options=["Good", "Bad", "Neutral"]
|
56 |
+
)
|
57 |
+
|
58 |
+
# Launch the interface
|
59 |
+
if __name__ == "__main__":
|
60 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
annotated-types==0.7.0
|
3 |
+
anyio==4.8.0
|
4 |
+
attrs==24.3.0
|
5 |
+
beautifulsoup4==4.12.3
|
6 |
+
certifi==2024.12.14
|
7 |
+
charset-normalizer==3.4.1
|
8 |
+
click==8.1.8
|
9 |
+
distro==1.9.0
|
10 |
+
duckduckgo_search==7.2.1
|
11 |
+
e2b==1.0.5
|
12 |
+
e2b-code-interpreter==1.0.3
|
13 |
+
exceptiongroup==1.2.2
|
14 |
+
fastapi==0.115.6
|
15 |
+
ffmpy==0.5.0
|
16 |
+
filelock==3.16.1
|
17 |
+
fsspec==2024.12.0
|
18 |
+
gradio==5.12.0
|
19 |
+
gradio_client==1.5.4
|
20 |
+
h11==0.14.0
|
21 |
+
httpcore==1.0.7
|
22 |
+
httpx==0.28.1
|
23 |
+
huggingface-hub==0.27.1
|
24 |
+
idna==3.10
|
25 |
+
Jinja2==3.1.5
|
26 |
+
jiter==0.8.2
|
27 |
+
lxml==5.3.0
|
28 |
+
markdown-it-py==3.0.0
|
29 |
+
markdownify==0.14.1
|
30 |
+
MarkupSafe==2.1.5
|
31 |
+
mdurl==0.1.2
|
32 |
+
numpy==2.2.1
|
33 |
+
openai==1.59.7
|
34 |
+
orjson==3.10.14
|
35 |
+
outcome==1.3.0.post0
|
36 |
+
packaging==24.2
|
37 |
+
pandas==2.2.3
|
38 |
+
pillow==11.1.0
|
39 |
+
primp==0.10.0
|
40 |
+
protobuf==5.29.3
|
41 |
+
pydantic==2.10.5
|
42 |
+
pydantic_core==2.27.2
|
43 |
+
pydub==0.25.1
|
44 |
+
Pygments==2.19.1
|
45 |
+
PySocks==1.7.1
|
46 |
+
python-dateutil==2.9.0.post0
|
47 |
+
python-dotenv==1.0.1
|
48 |
+
python-multipart==0.0.20
|
49 |
+
pytz==2024.2
|
50 |
+
PyYAML==6.0.2
|
51 |
+
regex==2024.11.6
|
52 |
+
requests==2.32.3
|
53 |
+
rich==13.9.4
|
54 |
+
ruff==0.9.2
|
55 |
+
safehttpx==0.1.6
|
56 |
+
safetensors==0.5.2
|
57 |
+
selenium==4.27.1
|
58 |
+
semantic-version==2.10.0
|
59 |
+
shellingham==1.5.4
|
60 |
+
six==1.17.0
|
61 |
+
smolagents==1.3.0
|
62 |
+
sniffio==1.3.1
|
63 |
+
sortedcontainers==2.4.0
|
64 |
+
soupsieve==2.6
|
65 |
+
starlette==0.41.3
|
66 |
+
tokenizers==0.21.0
|
67 |
+
tomlkit==0.13.2
|
68 |
+
tqdm==4.67.1
|
69 |
+
transformers==4.48.0
|
70 |
+
trio==0.28.0
|
71 |
+
trio-websocket==0.11.1
|
72 |
+
typer==0.15.1
|
73 |
+
typing_extensions==4.12.2
|
74 |
+
tzdata==2024.2
|
75 |
+
urllib3==2.3.0
|
76 |
+
uvicorn==0.34.0
|
77 |
+
websocket-client==1.8.0
|
78 |
+
websockets==14.1
|
79 |
+
wsproto==1.2.0
|