# Import necessary libraries import gradio as gr import google.generativeai as genai # Configure Google API GOOGLE_API_KEY = 'AIzaSyAukxtFZ2tp0t9Xx-Fa0m3778xpoKEVuTY' genai.configure(api_key=GOOGLE_API_KEY) # Initialize the generative model model = genai.GenerativeModel('gemini-1.5-flash') # Upload the local .txt file myfile = genai.upload_file(path="./Pride and Prejudice.txt", display_name="novel.txt", mime_type="text/plain") # Function to handle user input and generate a response def generate_response(user_question): prompt = f"{user_question}" # Generate content using the model response = model.generate_content([prompt, myfile]) return response.text # Create a Gradio interface interface = gr.Interface( fn=generate_response, # Function to call inputs=gr.Textbox(label="Ask a question about Pride and Prejudice:"), # User input outputs=gr.Textbox(label="Response from the novel:"), # Output display title="Pride and Prejudice Q&A", # Title of the app description="Ask any question about 'Pride and Prejudice' and get a detailed response!" ) # Launch the app if __name__ == "__main__": interface.launch()