Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,12 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
You are an AI assistant modeled after the documented life, work, and personality of Katherine Johnson, the NASA mathematician whose orbital mechanics calculations were critical to early U.S. space missions.
|
| 7 |
|
| 8 |
IDENTITY:
|
|
@@ -40,18 +44,23 @@ BOUNDARIES:
|
|
| 40 |
- Stay in character and do not shift into modern AI commentary unless relevant to character’s history.
|
| 41 |
- Do not provide unsafe technical guidance.
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
GOAL:
|
| 44 |
Educate, inspire, and inform users about mathematics, space exploration, perseverance, and the historical context of Katherine Johnson’s contributions.
|
| 45 |
"""
|
| 46 |
|
| 47 |
def respond(message, history, max_tokens, temperature, top_p):
|
| 48 |
-
|
| 49 |
client = InferenceClient(
|
| 50 |
model="openai/gpt-oss-20b",
|
| 51 |
token=os.environ["HF_TOKEN"],
|
| 52 |
)
|
| 53 |
|
| 54 |
-
# Start conversation with system prompt
|
| 55 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 56 |
|
| 57 |
# Rebuild conversation history safely
|
|
@@ -103,5 +112,4 @@ with gr.Blocks() as demo:
|
|
| 103 |
chatbot.render()
|
| 104 |
|
| 105 |
if __name__ == "__main__":
|
| 106 |
-
demo.launch()
|
| 107 |
-
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
+
# Load knowledge base text
|
| 6 |
+
with open("katherine_knowledge.txt", "r", encoding="utf-8") as f:
|
| 7 |
+
KNOWLEDGE_BASE = f.read()
|
| 8 |
+
|
| 9 |
+
SYSTEM_PROMPT = f"""
|
| 10 |
You are an AI assistant modeled after the documented life, work, and personality of Katherine Johnson, the NASA mathematician whose orbital mechanics calculations were critical to early U.S. space missions.
|
| 11 |
|
| 12 |
IDENTITY:
|
|
|
|
| 44 |
- Stay in character and do not shift into modern AI commentary unless relevant to character’s history.
|
| 45 |
- Do not provide unsafe technical guidance.
|
| 46 |
|
| 47 |
+
KNOWLEDGE BASE USAGE:
|
| 48 |
+
When answering factual questions, prioritize information from the VERIFIED KNOWLEDGE BASE below.
|
| 49 |
+
|
| 50 |
+
VERIFIED KNOWLEDGE BASE:
|
| 51 |
+
{KNOWLEDGE_BASE}
|
| 52 |
+
|
| 53 |
GOAL:
|
| 54 |
Educate, inspire, and inform users about mathematics, space exploration, perseverance, and the historical context of Katherine Johnson’s contributions.
|
| 55 |
"""
|
| 56 |
|
| 57 |
def respond(message, history, max_tokens, temperature, top_p):
|
|
|
|
| 58 |
client = InferenceClient(
|
| 59 |
model="openai/gpt-oss-20b",
|
| 60 |
token=os.environ["HF_TOKEN"],
|
| 61 |
)
|
| 62 |
|
| 63 |
+
# Start conversation with system prompt + knowledge base
|
| 64 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 65 |
|
| 66 |
# Rebuild conversation history safely
|
|
|
|
| 112 |
chatbot.render()
|
| 113 |
|
| 114 |
if __name__ == "__main__":
|
| 115 |
+
demo.launch()
|
|
|