Spaces:
Sleeping
Sleeping
wiring in a better summarizer - sheesh
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
from collections import Counter
|
2 |
import math
|
|
|
3 |
import gradio as gr
|
4 |
from datasets import load_dataset
|
5 |
from nltk.util import ngrams
|
@@ -159,6 +160,32 @@ def summarization(speech_key, _df):
|
|
159 |
return "\n\n".join(response)
|
160 |
|
161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
# Create a Gradio interface with blocks
|
163 |
with gr.Blocks() as demo:
|
164 |
df, written, spoken = load_transform_dataset()
|
@@ -253,9 +280,7 @@ with gr.Blocks() as demo:
|
|
253 |
# create a dropdown to select a speech from a president
|
254 |
run_summarization = gr.Button(value="Summarize")
|
255 |
fin_speech = gr.Textbox(label="Summarized Speech", type="text", lines=10)
|
256 |
-
run_summarization.click(
|
257 |
-
summarization, inputs=[speech, df_state], outputs=[fin_speech]
|
258 |
-
)
|
259 |
gr.Markdown(
|
260 |
"""
|
261 |
## Dive Deeper on Each President
|
|
|
1 |
from collections import Counter
|
2 |
import math
|
3 |
+
import os
|
4 |
import gradio as gr
|
5 |
from datasets import load_dataset
|
6 |
from nltk.util import ngrams
|
|
|
160 |
return "\n\n".join(response)
|
161 |
|
162 |
|
163 |
+
def streaming(speech_key, _df):
|
164 |
+
client = InferenceClient(token=os.environ["HF_TOKEN"])
|
165 |
+
speech = _df[_df["speech_key"] == speech_key]["speech_html"].values[0]
|
166 |
+
potus = speech_key.split(" - ")[0]
|
167 |
+
messages = []
|
168 |
+
for message in client.chat_completion(
|
169 |
+
model="meta-llama/Llama-3.1-8B-Instruct",
|
170 |
+
messages=[
|
171 |
+
{
|
172 |
+
"role": "system",
|
173 |
+
"content": "You are a legal scholar speaking to a class.",
|
174 |
+
},
|
175 |
+
{
|
176 |
+
"role": "user",
|
177 |
+
"content": f"The following speech is a State of the Union address from {potus}. Summarize it: {speech}",
|
178 |
+
},
|
179 |
+
],
|
180 |
+
max_tokens=1000,
|
181 |
+
stream=False,
|
182 |
+
):
|
183 |
+
# yield message.choices[0].delta.content
|
184 |
+
print(message)
|
185 |
+
# messages.append(message.choices[0].delta.content)
|
186 |
+
return "".join(messages)
|
187 |
+
|
188 |
+
|
189 |
# Create a Gradio interface with blocks
|
190 |
with gr.Blocks() as demo:
|
191 |
df, written, spoken = load_transform_dataset()
|
|
|
280 |
# create a dropdown to select a speech from a president
|
281 |
run_summarization = gr.Button(value="Summarize")
|
282 |
fin_speech = gr.Textbox(label="Summarized Speech", type="text", lines=10)
|
283 |
+
run_summarization.click(streaming, inputs=[speech, df_state], outputs=[fin_speech])
|
|
|
|
|
284 |
gr.Markdown(
|
285 |
"""
|
286 |
## Dive Deeper on Each President
|