Spaces:
Build error
Build error
Update app.py
Browse files
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
|
| 99 |
try:
|
| 100 |
# Use custom API key if provided, otherwise use default
|
| 101 |
-
api_key =
|
| 102 |
|
| 103 |
# Create a client with the appropriate API key
|
| 104 |
-
current_client =
|
| 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
|
| 149 |
-
|
| 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=
|
| 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=[
|