Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files3 unmodified lines4567891035 unmodified lines464748495051525354555657585960616263646566676869707172737470 unmodified lines14514614714814915015115215315415515615723 unmodified lines1811821831841851861871881891901911921933 unmodified linesfrom sentence_transformers import SentenceTransformerimport faissimport numpy as npfrom 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 linesbackground-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 (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 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)if user_query:# Check if there are any chunks in the indexif not chunks:23 unmodified linesfor chunk in retrieved_chunks:st.write(chunk)# Combine the retrieved chunks with the query and generate a response using Hugging Facecombined_input = " ".join(retrieved_chunks) + " " + user_queryresponse = generator(combined_input, max_length=200, num_return_sequences=1)[0]['generated_text']# Display the generated response in white textst.subheader("Generated Response")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)3 unmodified lines4567891035 unmodified lines464748495051525354555657585960616263646566676870 unmodified lines13914014114214314414514614714814915015123 unmodified lines1751761771781791801811821831841851861871881891901911921933 unmodified linesfrom sentence_transformers import SentenceTransformerimport faissimport numpy as npfrom groq import Client # Ensure you're importing the correct Groq client# Set background image and customize colorsbackground_image_url = "https://www.shutterstock.com/image-vector/artificial-intelligence-circuit-electric-line-600nw-2465096659.jpg"35 unmodified linesbackground-color: green;color: white;}}/* Set query input block background color to white */.stTextInput input {{background-color: white;color: black;}}</style>""",unsafe_allow_html=True)# Load Hugging Face SecretsHUGGINGFACE_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)# 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")# 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 indexif not chunks:23 unmodified linesfor chunk in retrieved_chunks:st.write(chunk)# Combine the retrieved chunks with the query and generate a response using Groqcombined_input = " ".join(retrieved_chunks) + user_query# Generate the response using Groq's correct API methodtry:# Assuming the correct Groq method is `generate_response` (adjust as per your API)response = groq_client.generate_response(model="llama3-8b-8192", prompt=combined_input, max_tokens=200)# Display the generated responsest.subheader("Generated Response")st.write(response["text"])except Exception as e:st.error(f"Error generating response: {e}")# Footerst.markdown("<div class='footer'>Created by Shamil Shahbaz</div>", unsafe_allow_html=True)
app.py+19-19