Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from smolagents import CodeAgent, HfApiModel, tool
|
| 2 |
import yaml
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
| 5 |
# Define a tool to generate motivational quotes
|
| 6 |
@tool
|
|
@@ -17,10 +18,17 @@ def get_motivational_quote() -> str:
|
|
| 17 |
return random.choice(quotes)
|
| 18 |
|
| 19 |
# Model setup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
model = HfApiModel(
|
| 21 |
-
max_tokens=
|
| 22 |
-
temperature=0.
|
| 23 |
-
model_id=
|
| 24 |
)
|
| 25 |
|
| 26 |
# Load prompt templates
|
|
@@ -43,15 +51,16 @@ def chat_with_agent(user_input, history):
|
|
| 43 |
if not user_input.strip():
|
| 44 |
return history + [[user_input, "Please enter a message to start the conversation!"]]
|
| 45 |
|
| 46 |
-
response =
|
| 47 |
-
|
|
|
|
| 48 |
return history
|
| 49 |
|
| 50 |
# Create Gradio Chat UI
|
| 51 |
with gr.Blocks() as demo:
|
| 52 |
gr.Markdown("### Welcome to MotivationAgent! 🌟\nType a message to receive a motivational quote or an uplifting response.")
|
| 53 |
|
| 54 |
-
chatbot = gr.Chatbot(label="MotivationAgent")
|
| 55 |
user_input = gr.Textbox(placeholder="Ask me for motivation... (e.g., 'I need inspiration')")
|
| 56 |
|
| 57 |
submit_btn = gr.Button("Send")
|
|
@@ -59,4 +68,3 @@ with gr.Blocks() as demo:
|
|
| 59 |
|
| 60 |
demo.launch()
|
| 61 |
|
| 62 |
-
|
|
|
|
| 1 |
from smolagents import CodeAgent, HfApiModel, tool
|
| 2 |
import yaml
|
| 3 |
import gradio as gr
|
| 4 |
+
import requests
|
| 5 |
|
| 6 |
# Define a tool to generate motivational quotes
|
| 7 |
@tool
|
|
|
|
| 18 |
return random.choice(quotes)
|
| 19 |
|
| 20 |
# Model setup
|
| 21 |
+
API_URL = "https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud"
|
| 22 |
+
HEADERS = {"Authorization": f"Bearer YOUR_HF_API_KEY"}
|
| 23 |
+
|
| 24 |
+
def query(payload):
|
| 25 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
| 26 |
+
return response.json()
|
| 27 |
+
|
| 28 |
model = HfApiModel(
|
| 29 |
+
max_tokens=512, # Reduced max_tokens for stability
|
| 30 |
+
temperature=0.7,
|
| 31 |
+
model_id=API_URL
|
| 32 |
)
|
| 33 |
|
| 34 |
# Load prompt templates
|
|
|
|
| 51 |
if not user_input.strip():
|
| 52 |
return history + [[user_input, "Please enter a message to start the conversation!"]]
|
| 53 |
|
| 54 |
+
response = query({"inputs": user_input, "parameters": {"max_tokens": 100}})
|
| 55 |
+
bot_response = response.get("generated_text", "Sorry, I couldn't generate a response.")
|
| 56 |
+
history.append([user_input, bot_response])
|
| 57 |
return history
|
| 58 |
|
| 59 |
# Create Gradio Chat UI
|
| 60 |
with gr.Blocks() as demo:
|
| 61 |
gr.Markdown("### Welcome to MotivationAgent! 🌟\nType a message to receive a motivational quote or an uplifting response.")
|
| 62 |
|
| 63 |
+
chatbot = gr.Chatbot(label="MotivationAgent", type="messages")
|
| 64 |
user_input = gr.Textbox(placeholder="Ask me for motivation... (e.g., 'I need inspiration')")
|
| 65 |
|
| 66 |
submit_btn = gr.Button("Send")
|
|
|
|
| 68 |
|
| 69 |
demo.launch()
|
| 70 |
|
|
|