Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# --- Load knowledge base from repo at startup ---
|
| 5 |
with open("knowledge.txt", "r", encoding="utf-8") as f:
|
|
@@ -27,14 +31,17 @@ def chat(user_input):
|
|
| 27 |
if user_input.lower() in knowledge_base.lower():
|
| 28 |
return "π Based on knowledge base: " + user_input
|
| 29 |
|
| 30 |
-
# Fallback to Gemini model
|
| 31 |
-
genai.api_key = global_api_key
|
| 32 |
try:
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
)
|
| 37 |
-
return response.
|
| 38 |
except Exception as e:
|
| 39 |
return f"β Error calling Gemini model: {e}"
|
| 40 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import faiss
|
| 4 |
+
from sentence_transformers import SentenceTransformer
|
| 5 |
+
from google import genai
|
| 6 |
+
from google.genai import types
|
| 7 |
|
| 8 |
# --- Load knowledge base from repo at startup ---
|
| 9 |
with open("knowledge.txt", "r", encoding="utf-8") as f:
|
|
|
|
| 31 |
if user_input.lower() in knowledge_base.lower():
|
| 32 |
return "π Based on knowledge base: " + user_input
|
| 33 |
|
| 34 |
+
# Fallback to Gemini model using your provided code style
|
|
|
|
| 35 |
try:
|
| 36 |
+
client = genai.Client(api_key=global_api_key)
|
| 37 |
+
response = client.models.generate_content(
|
| 38 |
+
model="gemini-2.5-flash",
|
| 39 |
+
contents=user_input,
|
| 40 |
+
config=types.GenerateContentConfig(
|
| 41 |
+
thinking_config=types.ThinkingConfig(thinking_budget=0)
|
| 42 |
+
),
|
| 43 |
)
|
| 44 |
+
return response.text
|
| 45 |
except Exception as e:
|
| 46 |
return f"β Error calling Gemini model: {e}"
|
| 47 |
|