Update app.py
Browse files
app.py
CHANGED
|
@@ -39,11 +39,11 @@ TOPICS = [
|
|
| 39 |
"Other"
|
| 40 |
]
|
| 41 |
|
| 42 |
-
# Improved prompt template for
|
| 43 |
def create_prompt(personality, level, topic):
|
| 44 |
-
return f"Explain {topic} in Plutus for a {level} programmer with {personality} traits.
|
| 45 |
|
| 46 |
-
# Response function with improved
|
| 47 |
def generate_response(personality, level, topic):
|
| 48 |
try:
|
| 49 |
logger.info("Processing selections...")
|
|
@@ -58,9 +58,9 @@ def generate_response(personality, level, topic):
|
|
| 58 |
"streamer": streamer,
|
| 59 |
"max_new_tokens": 600, # Increased to avoid cut-offs
|
| 60 |
"do_sample": True,
|
| 61 |
-
"temperature": 0.
|
| 62 |
-
"top_p": 0.
|
| 63 |
-
"repetition_penalty": 1.
|
| 64 |
"eos_token_id": tokenizer.eos_token_id,
|
| 65 |
"pad_token_id": tokenizer.pad_token_id
|
| 66 |
}
|
|
@@ -87,7 +87,7 @@ with gr.Blocks(title="Cardano Plutus AI Assistant") as demo:
|
|
| 87 |
personality = gr.Dropdown(
|
| 88 |
choices=PERSONALITY_TYPES,
|
| 89 |
label="Personality Type",
|
| 90 |
-
value="
|
| 91 |
)
|
| 92 |
level = gr.Dropdown(
|
| 93 |
choices=PROGRAMMING_LEVELS,
|
|
@@ -97,7 +97,7 @@ with gr.Blocks(title="Cardano Plutus AI Assistant") as demo:
|
|
| 97 |
topic = gr.Dropdown(
|
| 98 |
choices=TOPICS,
|
| 99 |
label="Topic",
|
| 100 |
-
value="
|
| 101 |
)
|
| 102 |
|
| 103 |
generate_btn = gr.Button("Generate")
|
|
|
|
| 39 |
"Other"
|
| 40 |
]
|
| 41 |
|
| 42 |
+
# Improved prompt template for autism-friendly, focused response
|
| 43 |
def create_prompt(personality, level, topic):
|
| 44 |
+
return f"Explain {topic} in Plutus for a {level} programmer with {personality} traits. Use only basic words and clear examples. Use a physical object analogy (e.g., a lock or checklist) tied to {topic}. Avoid jargon like 'blockchain,' 'ledger,' 'Haskell,' 'decentralized,' 'cyber,' 'e-commerce,' 'formal verification,' or 'immutability.' Use short sentences (6-8 words). Use exactly 3 numbered points for key ideas. Each point must have 5-10 words. Bold the first word of each point. Structure the response: 2-sentence introduction, 3 numbered points, 1-sentence conclusion. For Autistic traits, use literal language, numbered lists, and **bold key terms**. Repeat key ideas for clarity. Avoid abstract terms or metaphors unless concrete. Do not repeat the topic or prompt. Do not simulate a conversation, ask questions, or discuss unrelated topics like blockchain or cybersecurity. Use a direct, instructional tone without 'I,' 'we,' or conversational phrases. End with a summary sentence on {topic}’s importance. Use double line breaks between introduction, points, and conclusion for readability."
|
| 45 |
|
| 46 |
+
# Response function with improved parameters
|
| 47 |
def generate_response(personality, level, topic):
|
| 48 |
try:
|
| 49 |
logger.info("Processing selections...")
|
|
|
|
| 58 |
"streamer": streamer,
|
| 59 |
"max_new_tokens": 600, # Increased to avoid cut-offs
|
| 60 |
"do_sample": True,
|
| 61 |
+
"temperature": 0.1, # Lowered for focused output
|
| 62 |
+
"top_p": 0.1, # Lowered for focused output
|
| 63 |
+
"repetition_penalty": 1.7, # Increased to prevent tangents
|
| 64 |
"eos_token_id": tokenizer.eos_token_id,
|
| 65 |
"pad_token_id": tokenizer.pad_token_id
|
| 66 |
}
|
|
|
|
| 87 |
personality = gr.Dropdown(
|
| 88 |
choices=PERSONALITY_TYPES,
|
| 89 |
label="Personality Type",
|
| 90 |
+
value="Autistic"
|
| 91 |
)
|
| 92 |
level = gr.Dropdown(
|
| 93 |
choices=PROGRAMMING_LEVELS,
|
|
|
|
| 97 |
topic = gr.Dropdown(
|
| 98 |
choices=TOPICS,
|
| 99 |
label="Topic",
|
| 100 |
+
value="Introduction to Validation"
|
| 101 |
)
|
| 102 |
|
| 103 |
generate_btn = gr.Button("Generate")
|