Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| from openai import OpenAI | |
| import os | |
| # Set MindsDB API key and Mind name | |
| your_minds_api_key = os.getenv("MINDSDB_API_KEY") # You may want to set this as an environment variable | |
| mind_name = "CVPR_Data" | |
| # Initialize OpenAI SDK pointing to MindsDB Cloud | |
| client = OpenAI( | |
| api_key=your_minds_api_key, | |
| base_url='https://mdb.ai/' | |
| ) | |
| # Streamlit app | |
| st.title("CVPR 2024 Research Paper Analysis Tool") | |
| st.write("Ask questions about research papers and get insights directly from the database.") | |
| # Input query | |
| user_query = st.text_input("Enter your question about the research papers:") | |
| # Trigger the query | |
| if st.button("Ask"): | |
| if user_query: | |
| st.write("Answering the question may take up to 30 seconds...") | |
| # Query the MindsDB model | |
| try: | |
| completion = client.chat.completions.create( | |
| model=mind_name, | |
| messages=[ | |
| {'role': 'user', 'content': user_query} | |
| ], | |
| stream=False | |
| ) | |
| # Display the response | |
| response = completion.choices[0].message.content | |
| st.write("Response:", response) | |
| except Exception as e: | |
| st.error("An error occurred while querying the model.") | |
| st.write(e) | |
| else: | |
| st.warning("Please enter a question.") | |