Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,90 +1,26 @@
|
|
1 |
-
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
-
|
4 |
-
|
5 |
-
import
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
prompt = "<s>[SYSTEM] {} [/SYSTEM]".format(system_instruction)
|
29 |
-
for user_prompt, bot_response in history:
|
30 |
-
prompt += f"[INST] {user_prompt} [/INST]{bot_response}</s> "
|
31 |
-
prompt += f"[INST] {message} [/INST]"
|
32 |
-
return prompt
|
33 |
-
|
34 |
-
def generate(prompt, history=[], temperature=0.1, max_new_tokens=10000, top_p=0.95, repetition_penalty=1.0):
|
35 |
-
global total_tokens_used
|
36 |
-
input_tokens = len(tokenizer.encode(prompt))
|
37 |
-
total_tokens_used += input_tokens
|
38 |
-
available_tokens = 32768 - total_tokens_used
|
39 |
-
|
40 |
-
if available_tokens <= 0:
|
41 |
-
yield f"Error: ์
๋ ฅ์ด ์ต๋ ํ์ฉ ํ ํฐ ์๋ฅผ ์ด๊ณผํฉ๋๋ค. Total tokens used: {total_tokens_used}"
|
42 |
-
return
|
43 |
-
|
44 |
-
formatted_prompt = format_prompt(prompt, history)
|
45 |
-
output_accumulated = ""
|
46 |
-
try:
|
47 |
-
stream = client.text_generation(formatted_prompt, temperature=temperature, max_new_tokens=min(max_new_tokens, available_tokens),
|
48 |
-
top_p=top_p, repetition_penalty=repetition_penalty, do_sample=True, seed=42, stream=True)
|
49 |
-
for response in stream:
|
50 |
-
output_part = response['generated_text'] if 'generated_text' in response else str(response)
|
51 |
-
output_accumulated += output_part
|
52 |
-
yield output_accumulated + f"\n\n---\nTotal tokens used: {total_tokens_used}"
|
53 |
-
except Exception as e:
|
54 |
-
yield f"Error: {str(e)}\nTotal tokens used: {total_tokens_used}"
|
55 |
-
|
56 |
-
mychatbot = gr.Chatbot(
|
57 |
-
avatar_images=["./user.png", "./botm.png"],
|
58 |
-
bubble_full_width=False,
|
59 |
-
show_label=False,
|
60 |
-
show_copy_button=True,
|
61 |
-
likeable=True,
|
62 |
-
)
|
63 |
-
|
64 |
-
|
65 |
-
examples = [
|
66 |
-
["๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ ๊ฒ.", []], # history ๊ฐ์ ๋น ๋ฆฌ์คํธ๋ก ์ ๊ณต
|
67 |
-
["๋ถ์ ๊ฒฐ๊ณผ ๋ณด๊ณ ์ ๋ค์ ์ถ๋ ฅํ ๊ฒ", []],
|
68 |
-
["์ถ์ฒ ์ข
๋ชฉ ์๋ ค์ค", []],
|
69 |
-
["๊ทธ ์ข
๋ชฉ ํฌ์ ์ ๋ง ์์ธกํด", []]
|
70 |
-
]
|
71 |
-
|
72 |
-
|
73 |
-
css = """
|
74 |
-
h1 {
|
75 |
-
font-size: 14px; /* ์ ๋ชฉ ๊ธ๊ผด ํฌ๊ธฐ๋ฅผ ์๊ฒ ์ค์ */
|
76 |
-
}
|
77 |
-
footer {visibility: hidden;}
|
78 |
-
"""
|
79 |
-
|
80 |
-
demo = gr.ChatInterface(
|
81 |
-
fn=generate,
|
82 |
-
chatbot=mychatbot,
|
83 |
-
title="๊ธ๋ก๋ฒ ์์ฐ(์ฃผ์,์ง์,์ํ,๊ฐ์์์ฐ,์ธํ ๋ฑ) ๋ถ์ LLM: BloombAI",
|
84 |
-
retry_btn=None,
|
85 |
-
undo_btn=None,
|
86 |
-
css=css,
|
87 |
-
examples=examples
|
88 |
-
)
|
89 |
-
|
90 |
-
demo.queue().launch(show_api=False)
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from bs4 import BeautifulSoup
|
4 |
+
import re
|
5 |
+
|
6 |
+
def download_first_pdf():
|
7 |
+
url = "https://finance.naver.com/research/company_list.naver"
|
8 |
+
response = requests.get(url)
|
9 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
10 |
+
|
11 |
+
# ์ฒซ ๋ฒ์งธ PDF ๋งํฌ๋ฅผ ์ฐพ์ต๋๋ค.
|
12 |
+
pdf_link = soup.find('a', href=re.compile("\.pdf$"))
|
13 |
+
if pdf_link:
|
14 |
+
pdf_url = f"https://finance.naver.com{pdf_link['href']}"
|
15 |
+
return pdf_url
|
16 |
+
else:
|
17 |
+
return "PDF ๋งํฌ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
|
18 |
+
|
19 |
+
# Gradio ์ธํฐํ์ด์ค
|
20 |
+
with gr.Blocks() as app:
|
21 |
+
gr.Markdown("### ๋ค์ด๋ฒ ๊ธ์ต ๋ฆฌ์์น ๋ณด๊ณ ์ PDF ๋ค์ด๋ก๋")
|
22 |
+
btn_download = gr.Button("์ฒซ ๋ฒ์งธ PDF ๋ค์ด๋ก๋")
|
23 |
+
output = gr.Textbox(label="PDF ๋งํฌ")
|
24 |
+
btn_download.click(fn=download_first_pdf, outputs=output)
|
25 |
+
|
26 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|