Spaces:
Sleeping
Sleeping
add bs4
Browse files- app.py +8 -7
- requirements.txt +1 -1
app.py
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
-
import os
|
2 |
import json
|
3 |
-
import
|
4 |
import re
|
|
|
|
|
|
|
5 |
import gradio as gr
|
6 |
from spiralfilm import FilmCore, FilmConfig
|
7 |
|
@@ -22,13 +24,15 @@ async def summarize(input_text: str, input_url: str):
|
|
22 |
{input_text}
|
23 |
"""
|
24 |
elif input_url:
|
25 |
-
|
|
|
|
|
26 |
_prompt = f"""
|
27 |
以下の文章を要約してください。
|
28 |
{url_content}
|
29 |
"""
|
30 |
else:
|
31 |
-
|
32 |
|
33 |
config = FilmConfig(
|
34 |
"gpt-3.5-turbo-16k",
|
@@ -57,11 +61,8 @@ async def chat(input_text, input_url):
|
|
57 |
headers = {'API-Key': os.environ.get("TWINROOM_API_KEY")}
|
58 |
json_payload = json.dumps(payload)
|
59 |
response = requests.post(endpoint, headers=headers, data=json_payload)
|
60 |
-
print(response.text)
|
61 |
response_msgs = extract_texts(response.text)
|
62 |
-
print(response_msgs)
|
63 |
result = ''.join(response_msgs)
|
64 |
-
print(result)
|
65 |
return result
|
66 |
|
67 |
with gr.Blocks() as iface:
|
|
|
|
|
1 |
import json
|
2 |
+
import os
|
3 |
import re
|
4 |
+
import requests
|
5 |
+
|
6 |
+
from bs4 import BeautifulSoup
|
7 |
import gradio as gr
|
8 |
from spiralfilm import FilmCore, FilmConfig
|
9 |
|
|
|
24 |
{input_text}
|
25 |
"""
|
26 |
elif input_url:
|
27 |
+
res = requests.get(input_url)
|
28 |
+
soup = BeautifulSoup(res.text)
|
29 |
+
url_content = soup.find('title').text + '\n' + soup.find('body').text
|
30 |
_prompt = f"""
|
31 |
以下の文章を要約してください。
|
32 |
{url_content}
|
33 |
"""
|
34 |
else:
|
35 |
+
return "テキストかURLを入力してください。"
|
36 |
|
37 |
config = FilmConfig(
|
38 |
"gpt-3.5-turbo-16k",
|
|
|
61 |
headers = {'API-Key': os.environ.get("TWINROOM_API_KEY")}
|
62 |
json_payload = json.dumps(payload)
|
63 |
response = requests.post(endpoint, headers=headers, data=json_payload)
|
|
|
64 |
response_msgs = extract_texts(response.text)
|
|
|
65 |
result = ''.join(response_msgs)
|
|
|
66 |
return result
|
67 |
|
68 |
with gr.Blocks() as iface:
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
SpiralFilm==0.2.5
|
2 |
-
|
|
|
1 |
SpiralFilm==0.2.5
|
2 |
+
BeautifulSoup4=4.12.3
|