Spaces:
Runtime error
Runtime error
Download main.py from tharunk07/weatherapplication: direct link, hf CLI and curl.
- Browser
- Download file 977 Bytes
-
https://huggingface.co/spaces/tharunk07/weatherapplication/resolve/main/main.py
- Command line
-
hf download hf://spaces/tharunk07/weatherapplication/main.py
-
curl -L -o main.py https://huggingface.co/spaces/tharunk07/weatherapplication/resolve/main/main.py
977 Bytes
| from fastapi import FastAPI | |
| from dotenv import load_dotenv | |
| from langchain_google_genai import ChatGoogleGenerativeAI | |
| from langchain_core.prompts import ChatPromptTemplate | |
| from fastapi.responses import JSONResponse | |
| import os | |
| load_dotenv() | |
| app = FastAPI(swagger_ui_parameters={"syntaxHighlight": {"theme": "obsidian"}}) | |
| async def llm_chat(user_query): | |
| llm = ChatGoogleGenerativeAI( | |
| model="gemini-2.0-flash", | |
| temperature=0, | |
| max_tokens=None, | |
| timeout=None, | |
| max_retries=2, | |
| google_api_key = os.getenv("GEMINI_API_KEY") | |
| # other params... | |
| ) | |
| prompt = ChatPromptTemplate.from_messages([("user","{question}")]) | |
| chain = prompt | llm | |
| response = chain.invoke({"question":user_query}) | |
| print("Response>>",response.content) | |
| return JSONResponse({"type":"text","content":response.content}) | |
| async def home_page(): | |
| return JSONResponse("Welcome to the LLM API, New commit") |