Team Ai
Apppublic

Kvs9961/AI_Research_Explainer

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
AI_Research_Explainer.py95 linesDownload Raw Back to root
1from langchain_huggingface import ChatHuggingFace2from langchain_huggingface import HuggingFaceEndpoint3from langchain.prompts import load_prompt4from dotenv import load_dotenv5import streamlit as st6import re7import os8 9load_dotenv()10 11# Load the prompt template12templet = load_prompt('template.json')13 14# Set up Hugging Face endpoint15 16 17llm = HuggingFaceEndpoint(18    repo_id="deepseek-ai/DeepSeek-R1",19    task="text-generation",20    huggingfacehub_api_token=os.environ.get("HUGGINGFACEHUB_API_TOKEN")21)22 23model = ChatHuggingFace(llm=llm)24 25 26# Streamlit UI Header27st.header("🧠 AI Research Explainer")28 29# Inputs from user30topic = st.selectbox("Select Topic Name", [31    'Attention Is All You Need',32    'BERT: Pre-training of Deep Bidirectional Transformers',33    'GPT-3: Language Models are Few-Shot Learners',34    'Diffusion Models Beat GANs on Image Synthesis',35    'T5: Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer',36    'XLNet: Generalized Autoregressive Pretraining for Language Understanding',37    'RoBERTa: A Robustly Optimized BERT Pretraining Approach',38    'ERNIE: Enhanced Language Representation with Knowledge Integration',39    'LLaMA: Open and Efficient Foundation Models',40    'InstructGPT: Instruction-Tuned Language Models',41    'Vision Transformers (ViT): An Image is Worth 16x16 Words',42    'DETR: End-to-End Object Detection with Transformers',43    'Swin Transformer: Hierarchical Vision Transformer using Shifted Windows',44    'CLIP: Learning Transferable Visual Models from Natural Language Supervision',45    'DINO: Self-Supervised Learning with Vision Transformers',46    'StyleGAN2: Analyzing and Improving the Image Quality of GANs',47    'Stable Diffusion: High-Resolution Text-to-Image Synthesis',48    'DALL·E 2: Hierarchical Text-to-Image Generation',49    'Latent Diffusion Models for High-Resolution Image Synthesis',50    'Imagen: Photorealistic Text-to-Image Generation with Diffusion Models',51    'AlphaFold: Predicting Protein Structure with AI',52    'AlphaZero: Reinforcement Learning from Self-Play',53    'Gato: A Generalist Agent by DeepMind',54    'Flamingo: Visual-Language Few-Shot Learner',55    'Chinchilla: Efficient Scaling Laws for Language Models',56    'Mixture-of-Experts (MoE) Transformers',57    'PaLM: Scaling Language Models with Pathways',58    "Gemini 1.5: Google's Multimodal Transformer",59    'Claude 2: Constitutional AI by Anthropic',60    'LlamaIndex: Connecting LLMs with Structured and Unstructured Data'61])62 63style = st.selectbox("Select Explanation Type", ["Theory", "Technical", "Code-Oriented", "Mathematical"])64length = st.selectbox("Select Explanation Length", ["Short (1-2 paragraphs)", "Medium (3-5 paragraphs)", "Long (detailed explanation)"])65depth = st.selectbox("Select Explanation Style", ["Beginner friendly", "Intermediate", "Advanced"])66language = st.selectbox("Select Language", ["English", "Telugu", "Hindi"])67 68# Generate output when button is clicked69if st.button("Generate Explanation"):70    with st.spinner("Generating response..."):71        # Build the prompt72        response = templet.invoke({73            "topic": topic,74            "style": style,75            "length": length,76            "depth": depth,77            "language": language78        })79 80        # Get result from model81        result = model.invoke(response)82 83        # Remove <think>...</think> tags84        cleaned_output = re.sub(r'<think>.*?</think>', '', result.content, flags=re.DOTALL).strip()85 86        # Output box styling87        st.markdown("""88            <div style="background-color: rgba(255, 255, 255, 0.85); padding: 20px; border-radius: 10px; box-shadow: 0 0 10px rgba(0,0,0,0.3);">89        """, unsafe_allow_html=True)90 91        st.subheader("🔍 Explanation")92        st.write(cleaned_output)93 94        st.markdown("</div>", unsafe_allow_html=True)95