Spaces:
Sleeping
Sleeping
Upload 7 files
Browse files- Dockerfile +12 -0
- README.md +29 -0
- __init__.py +0 -0
- endpoints.py +74 -0
- fly.toml +17 -0
- requirements.txt +16 -0
- ui_main.py +93 -0
Dockerfile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11
|
| 2 |
+
# FROM python:3.11-slim-bullseye
|
| 3 |
+
|
| 4 |
+
WORKDIR /code
|
| 5 |
+
|
| 6 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 7 |
+
|
| 8 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 9 |
+
|
| 10 |
+
COPY . ./
|
| 11 |
+
|
| 12 |
+
CMD ["fastapi", "run", "endpoints.py", "--port", "8080"]
|
README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: AI Workflows
|
| 3 |
+
app_file: ui_main.py
|
| 4 |
+
sdk: streamlit
|
| 5 |
+
sdk_version: 1.35.0
|
| 6 |
+
pinned: false
|
| 7 |
+
python_version: 3.11.0
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
### Initial Setup
|
| 11 |
+
* Install python using conda by running the following command. `conda create -p venv python==3.11 -y`
|
| 12 |
+
* Activate conda profile `conda activate ./venv`
|
| 13 |
+
* Install required packages `./venv/bin/pip install -r requirements.txt`
|
| 14 |
+
* Copy .env.example to .env and enter the required values.
|
| 15 |
+
*
|
| 16 |
+
|
| 17 |
+
### Release process
|
| 18 |
+
##### API server
|
| 19 |
+
* Install flyctl by following instructions mentioned here https://fly.io/docs/flyctl/install/
|
| 20 |
+
* Run `fly deploy` to deploy the app.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
##### Streamlit UI
|
| 24 |
+
* Push code to main branch on huggingspace https://huggingface.co/spaces/beautiful-code/ai_workflows
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
### Running on local
|
| 28 |
+
* Streamlit app `streamlit run ui_main.py`
|
| 29 |
+
* FastAPI app `uvicorn endpoints:app --port=8080`
|
__init__.py
ADDED
|
File without changes
|
endpoints.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
import uvicorn
|
| 3 |
+
from fastapi import FastAPI, Query
|
| 4 |
+
from crew import til
|
| 5 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
+
from langsmith import Client
|
| 7 |
+
from typing import List, Optional
|
| 8 |
+
from pydantic import UUID4, BaseModel
|
| 9 |
+
load_dotenv()
|
| 10 |
+
|
| 11 |
+
description = """
|
| 12 |
+
API helps you do awesome stuff. 🚀
|
| 13 |
+
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
tags_metadata = [
|
| 17 |
+
{
|
| 18 |
+
"name": "til_feedback",
|
| 19 |
+
"description": "Gives the feedback on user's TIL content",
|
| 20 |
+
},
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
app = FastAPI(
|
| 24 |
+
title="Growthy AI Worflows",
|
| 25 |
+
description=description,
|
| 26 |
+
summary="Deadpool's favorite app. Nuff said.",
|
| 27 |
+
version="0.0.1",
|
| 28 |
+
openapi_tags=tags_metadata,
|
| 29 |
+
docs_url="/documentation",
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
app.add_middleware(
|
| 33 |
+
CORSMiddleware,
|
| 34 |
+
allow_origins=["*"],
|
| 35 |
+
allow_credentials=True,
|
| 36 |
+
allow_methods=["*"],
|
| 37 |
+
allow_headers=["*"],
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
@app.post("/til_feedback", tags=["til_feedback"])
|
| 41 |
+
async def til_feedback_kickoff(content: List[str]) -> til.TilFeedbackResponse:
|
| 42 |
+
separator = "\n* "
|
| 43 |
+
content[0] = "* " + content[0]
|
| 44 |
+
inputs = {"content": separator.join(content)}
|
| 45 |
+
result = til.TilCrew().kickoff(inputs)
|
| 46 |
+
return result
|
| 47 |
+
|
| 48 |
+
class Feedback(BaseModel):
|
| 49 |
+
helpful_score: Optional[float]
|
| 50 |
+
feedback_on: Optional[str]
|
| 51 |
+
|
| 52 |
+
@app.post("/til_feedback/{run_id}/feedback", tags=["til_feedback"])
|
| 53 |
+
async def capture_feedback(run_id: UUID4, feedback: Feedback) -> str:
|
| 54 |
+
print("Helful Score: ", feedback.helpful_score)
|
| 55 |
+
print("Feedback On: ", feedback.feedback_on)
|
| 56 |
+
client = Client()
|
| 57 |
+
client.create_feedback(
|
| 58 |
+
str(run_id),
|
| 59 |
+
key="helpful",
|
| 60 |
+
score=feedback.helpful_score,
|
| 61 |
+
source_info={"til": feedback.feedback_on},
|
| 62 |
+
type="api",
|
| 63 |
+
)
|
| 64 |
+
return "ok"
|
| 65 |
+
|
| 66 |
+
@app.get("/healthcheck")
|
| 67 |
+
async def read_root():
|
| 68 |
+
return {"status": "ok"}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
if __name__ == "__main__":
|
| 72 |
+
uvicorn.run(app, host="127.0.0.1", port=8080)
|
| 73 |
+
|
| 74 |
+
|
fly.toml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# fly.toml app configuration file generated for growthy-workflows on 2024-06-28T08:59:43+05:30
|
| 2 |
+
#
|
| 3 |
+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
| 4 |
+
#
|
| 5 |
+
|
| 6 |
+
app = "growthy-workflows"
|
| 7 |
+
primary_region = "sin"
|
| 8 |
+
|
| 9 |
+
[build]
|
| 10 |
+
|
| 11 |
+
[http_service]
|
| 12 |
+
internal_port = 8080
|
| 13 |
+
force_https = true
|
| 14 |
+
auto_stop_machines = true
|
| 15 |
+
auto_start_machines = true
|
| 16 |
+
min_machines_running = 0
|
| 17 |
+
processes = ["app"]
|
requirements.txt
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
python-dotenv
|
| 2 |
+
crewai
|
| 3 |
+
crewai_tools
|
| 4 |
+
langchain_community
|
| 5 |
+
langchain_google_genai
|
| 6 |
+
langchain_openai
|
| 7 |
+
streamlit
|
| 8 |
+
tavily-python
|
| 9 |
+
arxiv
|
| 10 |
+
semanticscholar
|
| 11 |
+
streamlit-extras
|
| 12 |
+
fastapi
|
| 13 |
+
uvicorn
|
| 14 |
+
fastapi_cors
|
| 15 |
+
langsmith
|
| 16 |
+
pytest
|
ui_main.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
from streamlit_extras.stylable_container import stylable_container
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from ui.article_recommendation import main as article_recommendor_main
|
| 6 |
+
from ui.research_paper import main as research_article_suggester_main
|
| 7 |
+
from ui.til_feedback import main as feedback_main
|
| 8 |
+
|
| 9 |
+
load_dotenv()
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
st.set_page_config(page_title='Multi-Page App', page_icon='📰', layout='wide')
|
| 13 |
+
|
| 14 |
+
def load_css(file_name):
|
| 15 |
+
with open(file_name) as f:
|
| 16 |
+
return f.read()
|
| 17 |
+
|
| 18 |
+
def main():
|
| 19 |
+
|
| 20 |
+
if 'page' not in st.session_state:
|
| 21 |
+
st.session_state.page = "main"
|
| 22 |
+
|
| 23 |
+
if st.session_state.page == "main":
|
| 24 |
+
show_main_page()
|
| 25 |
+
elif st.session_state.page == "article_recommendor":
|
| 26 |
+
article_recommendor_main()
|
| 27 |
+
elif st.session_state.page == "research_article_suggester":
|
| 28 |
+
research_article_suggester_main()
|
| 29 |
+
elif st.session_state.page == "feedback":
|
| 30 |
+
feedback_main()
|
| 31 |
+
|
| 32 |
+
def show_main_page():
|
| 33 |
+
|
| 34 |
+
css = load_css("ui/main.css")
|
| 35 |
+
st.markdown(f"<style>{css}</style>", unsafe_allow_html=True)
|
| 36 |
+
|
| 37 |
+
st.markdown('<div class="main-title">Welcome to the Multi-Page App!</div>', unsafe_allow_html=True)
|
| 38 |
+
st.markdown("---")
|
| 39 |
+
st.markdown('<div class="sub-header">Navigate to Specific Pages:</div>', unsafe_allow_html=True)
|
| 40 |
+
|
| 41 |
+
card_info = [
|
| 42 |
+
{"title": "Article Recommendor", "description": "Discover articles tailored to your interests.", "key": "article_recommendor"},
|
| 43 |
+
{"title": "Recent Article Suggester", "description": "Get suggestions for recent research articles.", "key": "research_article_suggester"},
|
| 44 |
+
{"title": "Feedback", "description": "Provide your valuable feedback.", "key": "feedback"},
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
num_cols = 3
|
| 48 |
+
num_rows = (len(card_info) + num_cols - 1) // num_cols
|
| 49 |
+
|
| 50 |
+
with stylable_container(
|
| 51 |
+
key="container_with_border",
|
| 52 |
+
css_styles="""
|
| 53 |
+
{
|
| 54 |
+
display: flex;
|
| 55 |
+
align-items: center;
|
| 56 |
+
flex-wrap: wrap;
|
| 57 |
+
}
|
| 58 |
+
""",
|
| 59 |
+
):
|
| 60 |
+
for row in range(num_rows):
|
| 61 |
+
cols = st.columns(num_cols)
|
| 62 |
+
for col in range(num_cols):
|
| 63 |
+
index = row * num_cols + col
|
| 64 |
+
if index < len(card_info):
|
| 65 |
+
card = card_info[index]
|
| 66 |
+
with cols[col]:
|
| 67 |
+
with stylable_container(
|
| 68 |
+
key="inside_container_with_border",
|
| 69 |
+
css_styles="""
|
| 70 |
+
{
|
| 71 |
+
height: 500px;
|
| 72 |
+
background-color: #f8f9fa;
|
| 73 |
+
border-radius: 10px;
|
| 74 |
+
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.1);
|
| 75 |
+
display: flex;
|
| 76 |
+
justify-content: center;
|
| 77 |
+
align-items: center;
|
| 78 |
+
flex-wrap: wrap;
|
| 79 |
+
padding:10px;
|
| 80 |
+
""",
|
| 81 |
+
):
|
| 82 |
+
st.markdown(
|
| 83 |
+
f'''
|
| 84 |
+
<div class="card">
|
| 85 |
+
<h2>{card["title"]}</h2>
|
| 86 |
+
<p>{card["description"]}</p>
|
| 87 |
+
</div>
|
| 88 |
+
''', unsafe_allow_html=True)
|
| 89 |
+
if st.button(f"Go to {card['title']}", key=card["key"]):
|
| 90 |
+
st.session_state.page = card["key"]
|
| 91 |
+
|
| 92 |
+
if __name__ == '__main__':
|
| 93 |
+
main()
|