subashpoudel commited on
Commit
85a68fb
·
1 Parent(s): be3a5c4

Inferenced with web page

Browse files
.gitignore CHANGED
@@ -1,2 +1,4 @@
1
  myenv
2
  .env
 
 
 
1
  myenv
2
  .env
3
+ static
4
+ templates
__pycache__/main.cpython-312.pyc CHANGED
Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ
 
main.py CHANGED
@@ -2,18 +2,88 @@ from fastapi import FastAPI
2
  from pydantic import BaseModel
3
  from my_agent.agent import build_graph
4
  import pandas as pd
 
5
 
6
  app = FastAPI()
7
  graph = build_graph()
8
 
9
- # Optional: define input schema
10
  class RequestInput(BaseModel):
11
- # query: list =[ "I want to make a promotional video of restaurant near lakeside"]
12
  query: list
 
13
 
14
 
15
  @app.post("/run")
16
  def run_graph(input_data: RequestInput):
17
  result = graph.invoke({'topic' : input_data.query})
18
- return {'returned_story': result['final_story']}
19
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from pydantic import BaseModel
3
  from my_agent.agent import build_graph
4
  import pandas as pd
5
+ from typing import Optional
6
 
7
  app = FastAPI()
8
  graph = build_graph()
9
 
 
10
  class RequestInput(BaseModel):
 
11
  query: list
12
+ preferred_topics: Optional[list] = []
13
 
14
 
15
  @app.post("/run")
16
  def run_graph(input_data: RequestInput):
17
  result = graph.invoke({'topic' : input_data.query})
18
+ return {'final_story': result['final_story']}
19
+
20
+
21
+ # *********************INFERENCING PART****************************
22
+ # import asyncio
23
+ # from fastapi import FastAPI, Request, Form
24
+ # from fastapi.responses import HTMLResponse
25
+ # from fastapi.staticfiles import StaticFiles
26
+ # from fastapi.templating import Jinja2Templates
27
+ # from my_agent.agent import build_graph
28
+ # from starlette.concurrency import run_in_threadpool
29
+
30
+ # app = FastAPI()
31
+ # graph = build_graph()
32
+
33
+ # app.mount("/static", StaticFiles(directory="static"), name="static")
34
+ # templates = Jinja2Templates(directory="templates")
35
+
36
+ # # Store session state in memory (simple approach)
37
+ # session_data = {
38
+ # "topic": [],
39
+ # "preferred_topics": [],
40
+ # }
41
+
42
+ # @app.get("/", response_class=HTMLResponse)
43
+ # def get_home(request: Request):
44
+ # return templates.TemplateResponse("index.html", {"request": request})
45
+
46
+ # @app.post("/submit", response_class=HTMLResponse)
47
+ # async def handle_query(request: Request, user_query: str = Form(...)):
48
+ # session_data["topic"] = [user_query]
49
+ # result = graph.invoke({"topic": session_data["topic"]})
50
+ # brainstorming = result.get("brainstroming_topics", [{}])[-1].values()
51
+ # return templates.TemplateResponse("index.html", {
52
+ # "request": request,
53
+ # "topics": brainstorming,
54
+ # "story": None,
55
+ # "show_buttons": True
56
+ # })
57
+
58
+ # @app.post("/select", response_class=HTMLResponse)
59
+ # async def select_topics(request: Request, selected_topics: list[str] = Form(...), action: str = Form(...)):
60
+ # session_data["preferred_topics"].append(selected_topics)
61
+
62
+ # if action == "go_deeper":
63
+ # result = await run_in_threadpool(
64
+ # graph.invoke,
65
+ # {"topic": session_data["topic"], "preferred_topics": session_data["preferred_topics"]}
66
+ # )
67
+ # new_brainstorm = result.get("brainstroming_topics", [{}])[-1].values()
68
+ # print()
69
+ # print('*****RESPONSE IS GENERATED********')
70
+ # print()
71
+ # return templates.TemplateResponse("index.html", {
72
+ # "request": request,
73
+ # "topics": new_brainstorm,
74
+ # "story": None,
75
+ # "show_buttons": True
76
+ # })
77
+
78
+ # elif action == "generate_final_story":
79
+ # result = await run_in_threadpool(
80
+ # graph.invoke,
81
+ # {"topic": session_data["topic"], "preferred_topics": session_data["preferred_topics"]}
82
+ # )
83
+ # return templates.TemplateResponse("index.html", {
84
+ # "request": request,
85
+ # "topics": [],
86
+ # "story": result.get("final_story"),
87
+ # "show_buttons": False
88
+ # })
89
+
my_agent/utils/__pycache__/data_loader.cpython-312.pyc CHANGED
Binary files a/my_agent/utils/__pycache__/data_loader.cpython-312.pyc and b/my_agent/utils/__pycache__/data_loader.cpython-312.pyc differ
 
my_agent/utils/__pycache__/nodes.cpython-312.pyc CHANGED
Binary files a/my_agent/utils/__pycache__/nodes.cpython-312.pyc and b/my_agent/utils/__pycache__/nodes.cpython-312.pyc differ
 
my_agent/utils/data_loader.py CHANGED
@@ -1,8 +1,19 @@
 
 
 
 
 
 
 
 
1
  from datasets import load_dataset
2
 
 
 
 
 
 
3
  def load_influencer_data():
4
- dataset = load_dataset("subashdvorak/tiktok-agentic-story",revision="embedded")
5
- data= dataset['train'].add_faiss_index('embeddings')
6
  return data
7
 
8
 
 
1
+ # from datasets import load_dataset
2
+
3
+ # def load_influencer_data():
4
+ # dataset = load_dataset("subashdvorak/tiktok-agentic-story",revision="embedded")
5
+ # data= dataset['train'].add_faiss_index('embeddings')
6
+ # return data
7
+
8
+
9
  from datasets import load_dataset
10
 
11
+ print("Loading dataset and indexing FAISS...") # Optional: for debugging
12
+
13
+ dataset = load_dataset("subashdvorak/tiktok-agentic-story", revision="embedded")
14
+ data = dataset['train'].add_faiss_index('embeddings')
15
+
16
  def load_influencer_data():
 
 
17
  return data
18
 
19
 
my_agent/utils/nodes.py CHANGED
@@ -133,6 +133,34 @@ def select_preferred_topics(state: State)-> State:
133
  return state
134
 
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  def generate_final_story(state:State)-> State:
137
  template = f'''I want to create a detailed storyline for a video in the given topic. You have to provide me that storyline what to include in the video.
138
  Now, i am giving you the topic of the video. But the need is to generate the story focusing on the format that i'll provide to you.
 
133
  return state
134
 
135
 
136
+ # def select_preferred_topics(state: State) -> State:
137
+ # print("---API_feedback_mode---")
138
+
139
+ # if not state.brainstroming_topics:
140
+ # print("No brainstormed topics found.")
141
+ # state.carry_on = False
142
+ # return state
143
+
144
+ # # Get the latest set of brainstormed topics
145
+ # topic_values = list(state.brainstroming_topics[-1].values())
146
+ # print(f"Available topics: {topic_values}")
147
+
148
+ # # Ensure preferred_topics is well-formed
149
+ # if state.preferred_topics and isinstance(state.preferred_topics[-1], list):
150
+ # latest_selection = state.preferred_topics[-1]
151
+ # if latest_selection:
152
+ # print("User selected topics:")
153
+ # print(latest_selection)
154
+ # state.carry_on = True
155
+ # return state
156
+
157
+ # print("No preferred topics selected via API. Ending feedback loop.")
158
+ # state.carry_on = False
159
+ # return state
160
+
161
+
162
+
163
+
164
  def generate_final_story(state:State)-> State:
165
  template = f'''I want to create a detailed storyline for a video in the given topic. You have to provide me that storyline what to include in the video.
166
  Now, i am giving you the topic of the video. But the need is to generate the story focusing on the format that i'll provide to you.
requirements.txt CHANGED
@@ -10,3 +10,4 @@ uvicorn
10
  numpy
11
  pandas
12
  langchain_huggingface
 
 
10
  numpy
11
  pandas
12
  langchain_huggingface
13
+ python-multipart