Update app.py
Browse files
app.py
CHANGED
|
@@ -24,15 +24,14 @@ model = HfApiModel(
|
|
| 24 |
temperature=0.5, # Controls how creative or focused the response is.
|
| 25 |
# We use an alternative model endpoint to help if the primary model is busy.
|
| 26 |
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
|
| 27 |
-
# (To revert to the original model,
|
| 28 |
custom_role_conversions=None
|
| 29 |
)
|
| 30 |
|
| 31 |
# ------------------------------------------------------------------------------
|
| 32 |
# Define the simplify_text tool.
|
| 33 |
-
# This tool takes technical text and instructs the
|
| 34 |
-
# It tells the model to break complex ideas into simple sentences
|
| 35 |
-
# to provide a brief definition in parentheses.
|
| 36 |
@tool
|
| 37 |
def simplify_text(text: str) -> str:
|
| 38 |
"""
|
|
@@ -50,39 +49,4 @@ def simplify_text(text: str) -> str:
|
|
| 50 |
prompt = (
|
| 51 |
"Please read the following technical text and explain it in plain, everyday language as if you were talking to someone with little technical knowledge. "
|
| 52 |
"Break down complex ideas into simple, short sentences. If you need to use any technical terms, provide a brief definition in parentheses right after the term. "
|
| 53 |
-
"Do not use
|
| 54 |
-
f"Technical text:\n{text}\n\n"
|
| 55 |
-
"Simplified explanation:"
|
| 56 |
-
)
|
| 57 |
-
# Call the model with the prompt. The model should generate a simplified explanation.
|
| 58 |
-
response = model(prompt)
|
| 59 |
-
return response
|
| 60 |
-
|
| 61 |
-
# ------------------------------------------------------------------------------
|
| 62 |
-
# Load additional instructions from the 'prompts.yaml' file.
|
| 63 |
-
# These prompt templates help guide the model's behavior.
|
| 64 |
-
with open("prompts.yaml", 'r') as stream:
|
| 65 |
-
prompt_templates = yaml.safe_load(stream)
|
| 66 |
-
|
| 67 |
-
# ------------------------------------------------------------------------------
|
| 68 |
-
# Create our AI agent.
|
| 69 |
-
# The agent is built by combining the model with our tools.
|
| 70 |
-
# Here we include:
|
| 71 |
-
# - FinalAnswerTool: Packages the final answer.
|
| 72 |
-
# - simplify_text: Converts technical text into plain language.
|
| 73 |
-
agent = CodeAgent(
|
| 74 |
-
model=model,
|
| 75 |
-
tools=[
|
| 76 |
-
FinalAnswerTool(),
|
| 77 |
-
simplify_text
|
| 78 |
-
],
|
| 79 |
-
max_steps=6, # Limit the number of reasoning steps the agent can use.
|
| 80 |
-
verbosity_level=1, # A lower number keeps internal details minimal.
|
| 81 |
-
prompt_templates=prompt_templates
|
| 82 |
-
)
|
| 83 |
-
|
| 84 |
-
# ------------------------------------------------------------------------------
|
| 85 |
-
# Launch the interactive user interface.
|
| 86 |
-
# GradioUI creates a webpage where users can type in technical text and see the simplified version.
|
| 87 |
-
# The interface listens on all network addresses (0.0.0.0) on port 7860.
|
| 88 |
-
if __n
|
|
|
|
| 24 |
temperature=0.5, # Controls how creative or focused the response is.
|
| 25 |
# We use an alternative model endpoint to help if the primary model is busy.
|
| 26 |
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
|
| 27 |
+
# (To revert to the original model, use: model_id='Qwen/Qwen2.5-Coder-32B-Instruct')
|
| 28 |
custom_role_conversions=None
|
| 29 |
)
|
| 30 |
|
| 31 |
# ------------------------------------------------------------------------------
|
| 32 |
# Define the simplify_text tool.
|
| 33 |
+
# This tool takes technical text and instructs the LLM to explain it in plain language.
|
| 34 |
+
# It tells the model to break down complex ideas into simple sentences and explain technical terms in simple words.
|
|
|
|
| 35 |
@tool
|
| 36 |
def simplify_text(text: str) -> str:
|
| 37 |
"""
|
|
|
|
| 49 |
prompt = (
|
| 50 |
"Please read the following technical text and explain it in plain, everyday language as if you were talking to someone with little technical knowledge. "
|
| 51 |
"Break down complex ideas into simple, short sentences. If you need to use any technical terms, provide a brief definition in parentheses right after the term. "
|
| 52 |
+
"Do not use c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|