Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import google.generativeai as genai | |
| # Configure Gemini API | |
| genai.configure(api_key='AIzaSyBcGzp4xqhpM3K3g7J_2xAr55Sy_rE0n1g') | |
| model = genai.GenerativeModel('gemini-pro') | |
| def generate_response(user_message): | |
| try: | |
| # Use Gemini API to generate a response | |
| response = model.generate_content(user_message) | |
| # Check if the response has text | |
| if response.text: | |
| return response.text | |
| else: | |
| return "Error: The model generated an empty response." | |
| except Exception as e: | |
| return f"An error occurred: {str(e)}" | |
| # Create Gradio interface | |
| iface = gr.Interface( | |
| fn=generate_response, | |
| inputs=gr.Textbox(lines=2, placeholder="Enter your question here..."), | |
| outputs=gr.Textbox(label="Gemini's Response"), | |
| title="Gemini QA System", | |
| description="Ask a question and get an answer from Gemini AI.", | |
| examples=[ | |
| ["What is the capital of France?"], | |
| ["Explain quantum computing in simple terms."] | |
| ] | |
| ) | |
| # Launch the interface | |
| iface.launch(debug=True) |