darsoarafa commited on
Commit
dbd3919
·
verified ·
1 Parent(s): 0ec8056

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -95,13 +95,13 @@ def get_quran_verse(surah, verse):
95
  }
96
 
97
  # Function to generate response using AI
98
- def generate_response(prompt, custom_api_key=None):
99
  try:
100
  # Use custom API key if provided, otherwise use default
101
- api_key = custom_api_key if custom_api_key else GEMINI_API_KEY
102
 
103
  # Create a client with the appropriate API key
104
- current_client = client # genai.Client(api_key=api_key)
105
 
106
  # Append Quran text to the user's prompt
107
  full_prompt = f"{prompt}\n\nHere is the complete Quran text to use as reference:\n{QURAN_TEXT}"
@@ -145,9 +145,8 @@ def update_api_key(api_key):
145
  return f"❌ Invalid API key: {str(e)}"
146
 
147
  # Gradio interface function
148
- def quran_helper(prompt, api_key):
149
- # Generate AI response with the provided API key (if any)
150
- response = generate_response(prompt, api_key if api_key else None)
151
 
152
  verses = response.get("verses", [])
153
  final_answer = response.get("final_answer", "No final answer provided")
@@ -202,7 +201,7 @@ with gr.Blocks(theme="soft") as demo:
202
  submit_btn = gr.Button("Submit")
203
  output = gr.Markdown(label="Response")
204
 
205
- submit_btn.click(quran_helper, inputs=[prompt_input, api_key_input], outputs=output)
206
 
207
  gr.Examples(
208
  examples=[
 
95
  }
96
 
97
  # Function to generate response using AI
98
+ def generate_response(prompt):
99
  try:
100
  # Use custom API key if provided, otherwise use default
101
+ api_key = GEMINI_API_KEY
102
 
103
  # Create a client with the appropriate API key
104
+ current_client = genai.Client(api_key=api_key)
105
 
106
  # Append Quran text to the user's prompt
107
  full_prompt = f"{prompt}\n\nHere is the complete Quran text to use as reference:\n{QURAN_TEXT}"
 
145
  return f"❌ Invalid API key: {str(e)}"
146
 
147
  # Gradio interface function
148
+ def quran_helper(prompt):
149
+ response = generate_response(prompt)
 
150
 
151
  verses = response.get("verses", [])
152
  final_answer = response.get("final_answer", "No final answer provided")
 
201
  submit_btn = gr.Button("Submit")
202
  output = gr.Markdown(label="Response")
203
 
204
+ submit_btn.click(quran_helper, inputs=prompt_input, outputs=output)
205
 
206
  gr.Examples(
207
  examples=[