Spaces:
Running
Running
🍌🐒
commited on
Commit
·
3c10197
1
Parent(s):
092270e
Initial commit
Browse files- Dockerfile +57 -0
- README.md +46 -3
- app.py +116 -0
- requirements.txt +25 -0
Dockerfile
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /code
|
| 4 |
+
|
| 5 |
+
# Install system dependencies
|
| 6 |
+
RUN apt-get update && apt-get install -y \
|
| 7 |
+
build-essential \
|
| 8 |
+
curl \
|
| 9 |
+
software-properties-common \
|
| 10 |
+
git \
|
| 11 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
+
|
| 13 |
+
# Install Chrome dependencies for playwright
|
| 14 |
+
RUN apt-get update && apt-get install -y \
|
| 15 |
+
libnss3 \
|
| 16 |
+
libnspr4 \
|
| 17 |
+
libatk1.0-0 \
|
| 18 |
+
libatk-bridge2.0-0 \
|
| 19 |
+
libcups2 \
|
| 20 |
+
libdrm2 \
|
| 21 |
+
libxkbcommon0 \
|
| 22 |
+
libxcomposite1 \
|
| 23 |
+
libxdamage1 \
|
| 24 |
+
libxfixes3 \
|
| 25 |
+
libxrandr2 \
|
| 26 |
+
libgbm1 \
|
| 27 |
+
libasound2 \
|
| 28 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 29 |
+
|
| 30 |
+
# Copy requirements first for better caching
|
| 31 |
+
COPY requirements.txt .
|
| 32 |
+
|
| 33 |
+
# Install Python dependencies
|
| 34 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 35 |
+
|
| 36 |
+
# Install playwright browsers
|
| 37 |
+
RUN playwright install chromium
|
| 38 |
+
RUN playwright install-deps chromium
|
| 39 |
+
|
| 40 |
+
# Copy the rest of the application
|
| 41 |
+
COPY . .
|
| 42 |
+
|
| 43 |
+
# Create necessary directories with proper permissions
|
| 44 |
+
RUN mkdir -p db logs projects screenshots pdfs && \
|
| 45 |
+
chmod 777 db logs projects screenshots pdfs
|
| 46 |
+
|
| 47 |
+
# Set environment variables
|
| 48 |
+
ENV PYTHONUNBUFFERED=1
|
| 49 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 50 |
+
ENV GRADIO_SERVER_PORT=7860
|
| 51 |
+
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 52 |
+
|
| 53 |
+
# Expose port for Gradio
|
| 54 |
+
EXPOSE 7860
|
| 55 |
+
|
| 56 |
+
# Command to run the application
|
| 57 |
+
CMD ["python", "app.py"]
|
README.md
CHANGED
|
@@ -1,12 +1,55 @@
|
|
| 1 |
---
|
| 2 |
title: Devika Assistant
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
license: apache-2.0
|
| 9 |
-
short_description:
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: Devika Assistant
|
| 3 |
+
emoji: 🤖
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
license: apache-2.0
|
| 9 |
+
short_description: An advanced AI coding assistant powered by GPT and Claude models.
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# 🤖 Devika AI Assistant
|
| 13 |
+
|
| 14 |
+
Devika is an advanced AI coding assistant that helps developers with various programming tasks. This Hugging Face Space provides a simplified interface to interact with Devika's core functionality.
|
| 15 |
+
|
| 16 |
+
## 🌟 Features
|
| 17 |
+
|
| 18 |
+
- **Code Generation**: Get help writing code in various programming languages
|
| 19 |
+
- **Project Creation**: Start new coding projects with best practices
|
| 20 |
+
- **Code Debugging**: Get assistance in finding and fixing bugs
|
| 21 |
+
- **Programming Q&A**: Ask questions about programming concepts and get detailed answers
|
| 22 |
+
|
| 23 |
+
## 🚀 How to Use
|
| 24 |
+
|
| 25 |
+
1. Type your coding request or question in the text input
|
| 26 |
+
2. Select your preferred language model:
|
| 27 |
+
- GPT-3.5 Turbo (default)
|
| 28 |
+
- GPT-4
|
| 29 |
+
- Claude-3-Opus
|
| 30 |
+
3. Choose your search engine:
|
| 31 |
+
- DuckDuckGo (default, no API key needed)
|
| 32 |
+
- Bing (requires API key)
|
| 33 |
+
- Google (requires API key)
|
| 34 |
+
4. Click "Send Message" and wait for Devika's response
|
| 35 |
+
|
| 36 |
+
## 🔑 API Keys
|
| 37 |
+
|
| 38 |
+
To use certain features, you'll need to set up API keys in the Space settings:
|
| 39 |
+
|
| 40 |
+
- For GPT models: Set up your OpenAI API key
|
| 41 |
+
- For Claude: Set up your Anthropic API key
|
| 42 |
+
- For search engines: Follow the setup guide in the [documentation](https://github.com/stitionai/devika/blob/main/docs/Installation/search_engine.md)
|
| 43 |
+
|
| 44 |
+
## 📝 Example Queries
|
| 45 |
+
|
| 46 |
+
- "Create a React component for a todo list"
|
| 47 |
+
- "Help me debug this Python function..."
|
| 48 |
+
- "How do I implement authentication in Express.js?"
|
| 49 |
+
- "Create a new Django project with user authentication"
|
| 50 |
+
|
| 51 |
+
## 🔗 Links
|
| 52 |
+
|
| 53 |
+
- [GitHub Repository](https://github.com/stitionai/devika)
|
| 54 |
+
- [Documentation](https://github.com/stitionai/devika/tree/main/docs)
|
| 55 |
+
- [Report Issues](https://github.com/stitionai/devika/issues)
|
app.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
load_dotenv() # Load environment variables from .env file
|
| 4 |
+
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from threading import Thread
|
| 7 |
+
import tiktoken
|
| 8 |
+
import logging
|
| 9 |
+
|
| 10 |
+
from src.config import Config
|
| 11 |
+
from src.logger import Logger
|
| 12 |
+
from src.project import ProjectManager
|
| 13 |
+
from src.state import AgentState
|
| 14 |
+
from src.agents import Agent
|
| 15 |
+
|
| 16 |
+
# Initialize core components
|
| 17 |
+
manager = ProjectManager()
|
| 18 |
+
AgentState = AgentState()
|
| 19 |
+
config = Config()
|
| 20 |
+
logger = Logger()
|
| 21 |
+
TIKTOKEN_ENC = tiktoken.get_encoding("cl100k_base")
|
| 22 |
+
|
| 23 |
+
# Configure logging
|
| 24 |
+
logging.basicConfig(level=logging.INFO)
|
| 25 |
+
logger = logging.getLogger(__name__)
|
| 26 |
+
|
| 27 |
+
def process_message(message, base_model="gpt-3.5-turbo", project_name="default", search_engine="duckduckgo"):
|
| 28 |
+
try:
|
| 29 |
+
agent = Agent(base_model=base_model, search_engine=search_engine.lower())
|
| 30 |
+
|
| 31 |
+
state = AgentState.get_latest_state(project_name)
|
| 32 |
+
if not state:
|
| 33 |
+
agent.execute(message, project_name)
|
| 34 |
+
else:
|
| 35 |
+
if AgentState.is_agent_completed(project_name):
|
| 36 |
+
agent.subsequent_execute(message, project_name)
|
| 37 |
+
else:
|
| 38 |
+
agent.execute(message, project_name)
|
| 39 |
+
|
| 40 |
+
# Get the latest messages
|
| 41 |
+
messages = manager.get_messages(project_name)
|
| 42 |
+
return messages[-1]["message"] if messages else "No response generated"
|
| 43 |
+
except Exception as e:
|
| 44 |
+
logger.error(f"Error processing message: {str(e)}")
|
| 45 |
+
return f"An error occurred: {str(e)}"
|
| 46 |
+
|
| 47 |
+
def create_gradio_interface():
|
| 48 |
+
with gr.Blocks(title="Devika AI Assistant", theme=gr.themes.Soft()) as interface:
|
| 49 |
+
gr.Markdown("""
|
| 50 |
+
# 🤖 Devika AI Assistant
|
| 51 |
+
|
| 52 |
+
Devika is an advanced AI coding assistant that helps you with:
|
| 53 |
+
- Writing and debugging code
|
| 54 |
+
- Creating new projects
|
| 55 |
+
- Answering programming questions
|
| 56 |
+
- And much more!
|
| 57 |
+
|
| 58 |
+
Simply type your request below and Devika will help you out.
|
| 59 |
+
""")
|
| 60 |
+
|
| 61 |
+
with gr.Row():
|
| 62 |
+
with gr.Column(scale=2):
|
| 63 |
+
message_input = gr.Textbox(
|
| 64 |
+
label="Your Message",
|
| 65 |
+
placeholder="Type your coding request here...",
|
| 66 |
+
lines=3
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
with gr.Row():
|
| 70 |
+
model_dropdown = gr.Dropdown(
|
| 71 |
+
choices=["gpt-3.5-turbo", "gpt-4", "claude-3-opus"],
|
| 72 |
+
value="gpt-3.5-turbo",
|
| 73 |
+
label="Model"
|
| 74 |
+
)
|
| 75 |
+
search_engine_dropdown = gr.Dropdown(
|
| 76 |
+
choices=["DuckDuckGo", "Bing", "Google"],
|
| 77 |
+
value="DuckDuckGo",
|
| 78 |
+
label="Search Engine"
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
submit_btn = gr.Button("Send Message", variant="primary")
|
| 82 |
+
|
| 83 |
+
with gr.Column(scale=3):
|
| 84 |
+
output_box = gr.Markdown(label="Devika's Response")
|
| 85 |
+
|
| 86 |
+
# Add examples
|
| 87 |
+
gr.Examples(
|
| 88 |
+
examples=[
|
| 89 |
+
["Create a React component for a todo list", "gpt-3.5-turbo", "DuckDuckGo"],
|
| 90 |
+
["Help me understand how to use Python decorators", "gpt-3.5-turbo", "DuckDuckGo"],
|
| 91 |
+
["Write a Node.js API endpoint for user authentication", "gpt-3.5-turbo", "DuckDuckGo"]
|
| 92 |
+
],
|
| 93 |
+
inputs=[message_input, model_dropdown, search_engine_dropdown],
|
| 94 |
+
outputs=output_box,
|
| 95 |
+
fn=lambda x, y, z: process_message(x, y, "default", z),
|
| 96 |
+
cache_examples=True
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
submit_btn.click(
|
| 100 |
+
fn=process_message,
|
| 101 |
+
inputs=[message_input, model_dropdown, gr.Textbox(value="default", visible=False), search_engine_dropdown],
|
| 102 |
+
outputs=output_box
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
return interface
|
| 106 |
+
|
| 107 |
+
# Create and launch the Gradio interface
|
| 108 |
+
interface = create_gradio_interface()
|
| 109 |
+
|
| 110 |
+
if __name__ == "__main__":
|
| 111 |
+
interface.launch(
|
| 112 |
+
server_name="0.0.0.0",
|
| 113 |
+
server_port=7860,
|
| 114 |
+
share=False,
|
| 115 |
+
debug=False
|
| 116 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask>=2.0.0
|
| 2 |
+
flask-cors>=4.0.0
|
| 3 |
+
flask-socketio>=5.3.0
|
| 4 |
+
gevent>=22.10.2
|
| 5 |
+
gradio>=4.19.2
|
| 6 |
+
tiktoken>=0.5.2
|
| 7 |
+
python-socketio>=5.11.0
|
| 8 |
+
fastlogging>=1.0.0
|
| 9 |
+
toml>=0.10.2
|
| 10 |
+
sqlmodel>=0.0.14
|
| 11 |
+
sqlalchemy>=2.0.0
|
| 12 |
+
playwright>=1.41.2
|
| 13 |
+
sentence-transformers>=2.5.1
|
| 14 |
+
urllib3>=2.0.0
|
| 15 |
+
requests>=2.31.0
|
| 16 |
+
colorama>=0.4.6
|
| 17 |
+
Jinja2>=3.1.2
|
| 18 |
+
mistletoe>=1.2.1
|
| 19 |
+
markdownify>=0.11.6
|
| 20 |
+
pytest-playwright>=0.4.3
|
| 21 |
+
openai>=1.12.0
|
| 22 |
+
anthropic>=0.18.1
|
| 23 |
+
duckduckgo-search>=4.4.3
|
| 24 |
+
orjson>=3.9.15
|
| 25 |
+
python-dotenv>=1.0.0
|