Spaces:
Sleeping
Sleeping
Zeggai Abdellah
commited on
Commit
·
7d1b69e
1
Parent(s):
d798578
add generate title to agentic
Browse files
main.py
CHANGED
|
@@ -6,6 +6,7 @@ Main entry point for the application
|
|
| 6 |
|
| 7 |
from fastapi import FastAPI, Query, HTTPException
|
| 8 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 9 |
import os
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
import logging
|
|
@@ -130,6 +131,28 @@ async def health_check():
|
|
| 130 |
return health_status
|
| 131 |
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
if __name__ == "__main__":
|
| 134 |
import uvicorn
|
| 135 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 6 |
|
| 7 |
from fastapi import FastAPI, Query, HTTPException
|
| 8 |
from fastapi.middleware.cors import CORSMiddleware
|
| 9 |
+
from langchain_google_genai import GoogleGenerativeAI
|
| 10 |
import os
|
| 11 |
from dotenv import load_dotenv
|
| 12 |
import logging
|
|
|
|
| 131 |
return health_status
|
| 132 |
|
| 133 |
|
| 134 |
+
@app.get("/generate_title")
|
| 135 |
+
def generate_title(first_question: str = Query(..., description="The first question to generate a title from")):
|
| 136 |
+
# Initialize the LLM - using the same model as in prepare_env.py
|
| 137 |
+
llm = GoogleGenerativeAI(
|
| 138 |
+
model="gemini-2.0-flash",
|
| 139 |
+
google_api_key=os.getenv("GOOGLE_API_KEY")
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
prompt = f"""Analyze this question and generate a very short title (3-5 words max):
|
| 143 |
+
1. If it's medical/vaccine-related: Create a professional clinical title
|
| 144 |
+
2. If non-medical: Create a general topic title
|
| 145 |
+
3. If unclear or greeting: Use "General Inquiry"
|
| 146 |
+
|
| 147 |
+
Always return just the title text, nothing else.
|
| 148 |
+
|
| 149 |
+
Question: {first_question}
|
| 150 |
+
|
| 151 |
+
Title:"""
|
| 152 |
+
|
| 153 |
+
title = llm.invoke(prompt)
|
| 154 |
+
return {"title": title.strip()}
|
| 155 |
+
|
| 156 |
if __name__ == "__main__":
|
| 157 |
import uvicorn
|
| 158 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|