Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -46,9 +46,10 @@ def json_from_text(text):
|
|
46 |
fix_json = JSONFixer()
|
47 |
return loads(fix_json.fix(json_out).line)
|
48 |
|
49 |
-
def generate_topics(user_input,num_topics,
|
50 |
-
|
51 |
-
|
|
|
52 |
subtopics = json_from_text(response_topics)
|
53 |
return subtopics
|
54 |
|
@@ -67,15 +68,14 @@ app.add_middleware(
|
|
67 |
class TopicInput(BaseModel):
|
68 |
user_input: str = Query(default="market research", description="input query to generate subtopics")
|
69 |
num_topics: int = Query(default=5, description="Number of subtopics to generate (default: 5)")
|
70 |
-
|
71 |
|
72 |
-
@app.get("/",tags=["Home"])
|
73 |
def api_home():
|
74 |
-
return {'detail': 'Welcome to FastAPI Subtopics API!
|
75 |
-
|
76 |
|
77 |
@app.post("/generate_topics")
|
78 |
async def create_topics(input: TopicInput):
|
79 |
-
topics = generate_topics(input.user_input, input.num_topics, input.
|
80 |
return {"topics": topics}
|
81 |
|
|
|
46 |
fix_json = JSONFixer()
|
47 |
return loads(fix_json.fix(json_out).line)
|
48 |
|
49 |
+
def generate_topics(user_input, num_topics, previous_queries):
|
50 |
+
previous_context = " -> ".join(previous_queries)
|
51 |
+
prompt = f"""create a list of {num_topics} subtopics to follow for conducting {user_input} in the context of {previous_context}, RETURN VALID PYTHON LIST"""
|
52 |
+
response_topics = together_response(prompt, model="meta-llama/Llama-3-8b-chat-hf", SysPrompt=None)
|
53 |
subtopics = json_from_text(response_topics)
|
54 |
return subtopics
|
55 |
|
|
|
68 |
class TopicInput(BaseModel):
|
69 |
user_input: str = Query(default="market research", description="input query to generate subtopics")
|
70 |
num_topics: int = Query(default=5, description="Number of subtopics to generate (default: 5)")
|
71 |
+
previous_queries: list[str] = Query(default=[], description="List of previous queries for context")
|
72 |
|
73 |
+
@app.get("/", tags=["Home"])
|
74 |
def api_home():
|
75 |
+
return {'detail': 'Welcome to FastAPI Subtopics API! Visit https://pvanand-generate-subtopics.hf.space/docs to test'}
|
|
|
76 |
|
77 |
@app.post("/generate_topics")
|
78 |
async def create_topics(input: TopicInput):
|
79 |
+
topics = generate_topics(input.user_input, input.num_topics, input.previous_queries)
|
80 |
return {"topics": topics}
|
81 |
|