Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import inspect
|
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
import asyncio
|
|
|
|
| 8 |
from llama_index.core.agent.workflow import AgentWorkflow
|
| 9 |
from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
|
| 10 |
from youtube_tool import youtube_transcript_tool, youtube_transcript_snippet_tool
|
|
@@ -31,7 +32,17 @@ class BasicAgent:
|
|
| 31 |
llm=self.llm,
|
| 32 |
)
|
| 33 |
def __call__(self, question: str) -> str:
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
#print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 37 |
#fixed_answer = "This is a default answer."
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
import asyncio
|
| 8 |
+
import nest_asyncio
|
| 9 |
from llama_index.core.agent.workflow import AgentWorkflow
|
| 10 |
from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
|
| 11 |
from youtube_tool import youtube_transcript_tool, youtube_transcript_snippet_tool
|
|
|
|
| 32 |
llm=self.llm,
|
| 33 |
)
|
| 34 |
def __call__(self, question: str) -> str:
|
| 35 |
+
try:
|
| 36 |
+
loop = asyncio.get_running_loop()
|
| 37 |
+
except RuntimeError:
|
| 38 |
+
loop = asyncio.new_event_loop()
|
| 39 |
+
asyncio.set_event_loop(loop)
|
| 40 |
+
|
| 41 |
+
# Fix for notebooks / AnyIO threads
|
| 42 |
+
nest_asyncio.apply(loop)
|
| 43 |
+
|
| 44 |
+
# Run async agent synchronously
|
| 45 |
+
return loop.run_until_complete(self.llamaindex_agent.run(question))
|
| 46 |
|
| 47 |
#print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 48 |
#fixed_answer = "This is a default answer."
|