Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files3 unmodified lines45677891035 unmodified lines46474849495051525354555657585960616263646165666768696667707172737470 unmodified lines14514614714814915015115215315414814915015515615723 unmodified lines1811821831801811821841851861871841881891861901911921933 unmodified linesfrom sentence_transformers import SentenceTransformerimport faissimport numpy as npfrom groq import Clientfrom transformers import pipeline # Use Hugging Face model instead of Groq
# Set background image and customize colorsbackground_image_url = "https://www.shutterstock.com/image-vector/artificial-intelligence-circuit-electric-line-600nw-2465096659.jpg"35 unmodified lines background-color: green; color: white; }}
/* Set query input block background color to white */ .stTextInput input {{ background-color: white; color: black; }}
/* Display generated response text in white */ .stWrite {{ color: white !important; }} </style> """, unsafe_allow_html=True)
# Load Hugging Face Secrets# Load Hugging Face Secrets (if needed for Hugging Face integration)HUGGINGFACE_KEY = os.getenv("HUGGINGFACE_KEY")if not HUGGINGFACE_KEY: st.error("Hugging Face API token not found. Please set it in the Hugging Face Secrets.")
# Initialize Groq clientgroq_client = Client(api_key=HUGGINGFACE_KEY)# Initialize Hugging Face pipeline for text generation (using GPT-2 or other models)generator = pipeline('text-generation', model='gpt-2', api_key=HUGGINGFACE_KEY)
# Load the SentenceTransformer model for embedding generationembedder = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')70 unmodified lines# User interface for Streamlitst.title("The Rise of Agentic AI RAG Application")
# Query input for the useruser_query = st.text_input("Enter your query:")
# Button to trigger document processingif st.button("Process PDF"): process_and_store_document(file_path)
# Query input for the useruser_query = st.text_input("Enter your query:")
if user_query: # Check if there are any chunks in the index if not chunks:23 unmodified lines for chunk in retrieved_chunks: st.write(chunk) # Combine the retrieved chunks with the query and generate a response using Groq combined_input = " ".join(retrieved_chunks) + user_query response = groq_client.generate(model="llama3-8b-8192", prompt=combined_input, max_tokens=200) # Combine the retrieved chunks with the query and generate a response using Hugging Face combined_input = " ".join(retrieved_chunks) + " " + user_query response = generator(combined_input, max_length=200, num_return_sequences=1)[0]['generated_text'] # Display the generated response # Display the generated response in white text st.subheader("Generated Response") st.write(response["text"]) st.markdown(f"<p style='color:white'>{response}</p>", unsafe_allow_html=True)
# Footerst.markdown("<div class='footer'>Created by Shamil Shahbaz</div>", unsafe_allow_html=True)app.py+17-13