Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import streamlit as st
|
|
| 2 |
import requests
|
| 3 |
from bs4 import BeautifulSoup
|
| 4 |
import trafilatura
|
| 5 |
-
from smolagents import
|
| 6 |
|
| 7 |
# Streamlit UI
|
| 8 |
def main():
|
|
@@ -51,13 +51,22 @@ def find_relevant_article(base_url, question):
|
|
| 51 |
|
| 52 |
# Step 5: Generate Answer using `smolagents`
|
| 53 |
def generate_answer(question, context):
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|
| 63 |
-
main()
|
|
|
|
| 2 |
import requests
|
| 3 |
from bs4 import BeautifulSoup
|
| 4 |
import trafilatura
|
| 5 |
+
from smolagents import create_agent
|
| 6 |
|
| 7 |
# Streamlit UI
|
| 8 |
def main():
|
|
|
|
| 51 |
|
| 52 |
# Step 5: Generate Answer using `smolagents`
|
| 53 |
def generate_answer(question, context):
|
| 54 |
+
"""Defines an AI agent to generate answers based on documentation context."""
|
| 55 |
+
|
| 56 |
+
def answer_logic(state):
|
| 57 |
+
"""Agent logic to answer based on context."""
|
| 58 |
+
return f"Based on the documentation, here is my answer: {state['context'][:500]}..." # Truncating for brevity
|
| 59 |
+
|
| 60 |
+
# Create the agent
|
| 61 |
+
agent = create_agent(
|
| 62 |
+
name="QA_Agent",
|
| 63 |
+
description="Answers questions based on documentation content.",
|
| 64 |
+
process=answer_logic,
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
# Run the agent
|
| 68 |
+
response = agent({"context": context, "question": question})
|
| 69 |
+
return response
|
| 70 |
|
| 71 |
if __name__ == "__main__":
|
| 72 |
+
main()
|