-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
50 lines (37 loc) · 1.87 KB
/
app.py
File metadata and controls
50 lines (37 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from dotenv import load_dotenv
load_dotenv() # Load environment variables from .env file
import streamlit as st
import os
import google.generativeai as genai
# Configure the Gemini API using the API key from the environment variable
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
# Function to load Gemini model and get a response
model = genai.GenerativeModel("gemini-pro")
chat = model.start_chat(history=[]) # Empty history for each new session
# Function to get a response from the Gemini model for football injury rehab questions
def get_gemini_response(question):
# Create a prompt that ensures the response is focused on football injury rehab
football_prompt = (
"You are a highly specialized rehabilitation assistant for football players. "
"Provide detailed advice for recovery, rehabilitation exercises, and injury management. "
"Question: " + question
)
# Get a response from the model with the specialized prompt
response = chat.send_message(football_prompt, stream=True)
return response
# Initialize Streamlit app settings
st.set_page_config(page_title="Football Injury Rehab Chatbot")
st.header("Football Injury Rehab Assistant")
# Input box for user to ask football injury-related questions
input_question = st.text_input("Ask your football injury rehab question:")
# Submit button to send the question
submit = st.button("Ask the question")
if submit and input_question:
# Get the response from the Gemini model
response = get_gemini_response(input_question)
# Display the response
st.subheader("Rehabilitation Advice")
for chunk in response:
st.write(chunk.text)
# Instruction message
st.info("Ask any question related to football injuries and rehab strategies. This chatbot provides advice on treatments, exercises, and recovery plans.")