app
Browse files
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
# ------------------ Load API Key ------------------
|
| 7 |
+
load_dotenv()
|
| 8 |
+
api_key = os.getenv("GEMINI_API_KEY")
|
| 9 |
+
|
| 10 |
+
if not api_key:
|
| 11 |
+
st.error("❌ Please set your GEMINI_API_KEY as a Hugging Face secret.")
|
| 12 |
+
else:
|
| 13 |
+
genai.configure(api_key=api_key)
|
| 14 |
+
|
| 15 |
+
# ------------------ App Config ------------------
|
| 16 |
+
st.set_page_config(page_title="Trending Research Chatbot", page_icon="🧠", layout="centered")
|
| 17 |
+
|
| 18 |
+
st.title("🧠 ResearchTrend-Gemini")
|
| 19 |
+
st.markdown("### Your AI assistant for trending research papers & videos 📈")
|
| 20 |
+
|
| 21 |
+
# ------------------ Chat History ------------------
|
| 22 |
+
if "messages" not in st.session_state:
|
| 23 |
+
st.session_state["messages"] = []
|
| 24 |
+
|
| 25 |
+
# ------------------ Display Chat ------------------
|
| 26 |
+
for msg in st.session_state["messages"]:
|
| 27 |
+
if msg["role"] == "user":
|
| 28 |
+
st.chat_message("user").markdown(msg["content"])
|
| 29 |
+
else:
|
| 30 |
+
st.chat_message("assistant").markdown(msg["content"])
|
| 31 |
+
|
| 32 |
+
# ------------------ User Input ------------------
|
| 33 |
+
user_input = st.chat_input("Ask about trending research papers or videos...")
|
| 34 |
+
|
| 35 |
+
if user_input:
|
| 36 |
+
st.chat_message("user").markdown(user_input)
|
| 37 |
+
st.session_state["messages"].append({"role": "user", "content": user_input})
|
| 38 |
+
|
| 39 |
+
# ------------- Super Prompt + User Query -------------
|
| 40 |
+
system_prompt = """
|
| 41 |
+
You are ResearchTrend-Gemini, an expert AI assistant that finds and explains
|
| 42 |
+
the latest trending research papers and YouTube videos on AI, ML, DL, Data Science,
|
| 43 |
+
Computer Vision, NLP, and Robotics.
|
| 44 |
+
|
| 45 |
+
When asked:
|
| 46 |
+
- Provide top 5 trending papers with titles, short summaries, topics, and possible arXiv IDs.
|
| 47 |
+
- Provide top 3 trending YouTube videos with title, short summary, and approximate upload time.
|
| 48 |
+
- If general questions are asked, respond as an AI research expert.
|
| 49 |
+
|
| 50 |
+
Use clean markdown formatting and emojis for clarity.
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
full_prompt = system_prompt + "\n\nUser: " + user_input
|
| 54 |
+
|
| 55 |
+
# ------------------ Gemini Response ------------------
|
| 56 |
+
try:
|
| 57 |
+
model = genai.GenerativeModel("gemini-1.5-pro")
|
| 58 |
+
response = model.generate_content(full_prompt)
|
| 59 |
+
output = response.text
|
| 60 |
+
|
| 61 |
+
st.chat_message("assistant").markdown(output)
|
| 62 |
+
st.session_state["messages"].append({"role": "assistant", "content": output})
|
| 63 |
+
|
| 64 |
+
except Exception as e:
|
| 65 |
+
st.error(f"⚠️ Error: {str(e)}")
|