Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,19 +10,13 @@ import json
|
|
| 10 |
|
| 11 |
def run_workflow(message):
|
| 12 |
try:
|
| 13 |
-
if 'files' not in message or not message['files']:
|
| 14 |
-
return "PDFファイルが選択されていません。", ""
|
| 15 |
-
|
| 16 |
file = message['files'][0]
|
| 17 |
-
|
| 18 |
-
if not file.name.lower().endswith('.pdf'):
|
| 19 |
-
return "選択されたファイルはPDFではありません。", ""
|
| 20 |
-
|
| 21 |
-
if file.size == 0:
|
| 22 |
-
return "選択されたPDFファイルが空です。", ""
|
| 23 |
-
|
| 24 |
text_message = message['text']
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
# PDFファイルをロードしてテキストを抽出
|
| 27 |
loader = UnstructuredPDFLoader(file)
|
| 28 |
data = loader.load()
|
|
@@ -112,27 +106,22 @@ iface = gr.Interface(
|
|
| 112 |
- gemini-1.5-flash
|
| 113 |
```
|
| 114 |
PDFファイルを入力として受け取り、Dify APIのワークフローを使用してファイルを処理し、結果を返す関数。
|
| 115 |
-
|
| 116 |
Args:
|
| 117 |
message (dict): 入力メッセージ。以下のキーを含む辞書。
|
| 118 |
- 'files' (list): アップロードされたPDFファイルのリスト。
|
| 119 |
- 'text' (str): テキストメッセージ。
|
| 120 |
-
|
| 121 |
Yields:
|
| 122 |
tuple: 以下の要素を含むタプル。
|
| 123 |
- raw_text (str): PDFファイルから抽出された生テキスト。
|
| 124 |
- assistant_message (str): アシスタントからのメッセージ。
|
| 125 |
- outputs (dict): APIレスポンスのデータ。
|
| 126 |
-
|
| 127 |
Returns:
|
| 128 |
tuple: 以下の要素を含むタプル。
|
| 129 |
- status (str): 処理の状態。"error" または "" (空文字列)。
|
| 130 |
- error_message (str): エラーメッセージ (エラーが発生した場合)。
|
| 131 |
- data (dict): APIレスポンスのデータ。
|
| 132 |
-
|
| 133 |
Raises:
|
| 134 |
Exception: 処理中にエラーが発生した場合。
|
| 135 |
-
|
| 136 |
Notes:
|
| 137 |
- 関数は非同期的に実行され、処理の進行状況に応じて段階的に結果を返す。
|
| 138 |
- `yield` を使用して、処理の途中経過を表示しながら、最終的な結果を返す。
|
|
|
|
| 10 |
|
| 11 |
def run_workflow(message):
|
| 12 |
try:
|
|
|
|
|
|
|
|
|
|
| 13 |
file = message['files'][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
text_message = message['text']
|
| 15 |
|
| 16 |
+
# PDFファイルが選択されているかチェック
|
| 17 |
+
if not file:
|
| 18 |
+
return "PDFファイルを選択してください。", ""
|
| 19 |
+
|
| 20 |
# PDFファイルをロードしてテキストを抽出
|
| 21 |
loader = UnstructuredPDFLoader(file)
|
| 22 |
data = loader.load()
|
|
|
|
| 106 |
- gemini-1.5-flash
|
| 107 |
```
|
| 108 |
PDFファイルを入力として受け取り、Dify APIのワークフローを使用してファイルを処理し、結果を返す関数。
|
|
|
|
| 109 |
Args:
|
| 110 |
message (dict): 入力メッセージ。以下のキーを含む辞書。
|
| 111 |
- 'files' (list): アップロードされたPDFファイルのリスト。
|
| 112 |
- 'text' (str): テキストメッセージ。
|
|
|
|
| 113 |
Yields:
|
| 114 |
tuple: 以下の要素を含むタプル。
|
| 115 |
- raw_text (str): PDFファイルから抽出された生テキスト。
|
| 116 |
- assistant_message (str): アシスタントからのメッセージ。
|
| 117 |
- outputs (dict): APIレスポンスのデータ。
|
|
|
|
| 118 |
Returns:
|
| 119 |
tuple: 以下の要素を含むタプル。
|
| 120 |
- status (str): 処理の状態。"error" または "" (空文字列)。
|
| 121 |
- error_message (str): エラーメッセージ (エラーが発生した場合)。
|
| 122 |
- data (dict): APIレスポンスのデータ。
|
|
|
|
| 123 |
Raises:
|
| 124 |
Exception: 処理中にエラーが発生した場合。
|
|
|
|
| 125 |
Notes:
|
| 126 |
- 関数は非同期的に実行され、処理の進行状況に応じて段階的に結果を返す。
|
| 127 |
- `yield` を使用して、処理の途中経過を表示しながら、最終的な結果を返す。
|