Spaces:
Sleeping
Sleeping
restructuring content and updating gradio
Browse files- app.py +23 -20
- poetry.lock +5 -5
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
from collections import Counter
|
2 |
import math
|
3 |
import os
|
@@ -170,15 +172,16 @@ def streaming(speech_key, _df):
|
|
170 |
messages=[
|
171 |
{
|
172 |
"role": "system",
|
173 |
-
"content": "You are a political scholar with a deep knowledge of State of the Union addresses. You are tasked with summarizing a speech from a given president. The
|
174 |
},
|
175 |
{
|
176 |
"role": "user",
|
177 |
-
"content": f"The following speech is a State of the Union address from {speech_info[0]} on {speech_info[1]}. Summarize it: {speech}",
|
178 |
},
|
179 |
],
|
180 |
-
max_tokens=
|
181 |
stream=True,
|
|
|
182 |
):
|
183 |
# yield message.choices[0].delta.content
|
184 |
# print(message)
|
@@ -203,6 +206,23 @@ with gr.Blocks() as demo:
|
|
203 |
"In addition to analyzing the content, this space also leverages the [Qwen/2.5-72B-Instruct](https://deepinfra.com/Qwen/Qwen2.5-72B-Instruct) model to summarize a speech. The model is tasked with providing a concise summary of a speech from a given president. To get a summary, go to the 'Summarize a Speech' tab."
|
204 |
)
|
205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
with gr.Tab(label="Speech Data"):
|
207 |
# Basic line chart showing the total number of words in each address
|
208 |
gr.Markdown(
|
@@ -317,21 +337,4 @@ with gr.Blocks() as demo:
|
|
317 |
# show a line chart of word count and ARI for a selected president
|
318 |
gr.Plot(plotly_word_and_ari, inputs=[president, df_state])
|
319 |
|
320 |
-
with gr.Tab(label="Summarize a Speech"):
|
321 |
-
gr.Markdown("## Summarize a Speech")
|
322 |
-
gr.Markdown(
|
323 |
-
"""
|
324 |
-
Context is king; get a summary of a State of the Union now that you've seen a bit more. Use the dropdown to select a speech from a president and click the button to summarize the speech. [Qwen/2.5-72B-Instruct](https://deepinfra.com/Qwen/Qwen2.5-72B-Instruct) will provide a concise summary of the speech with the proper historical and political context.
|
325 |
-
"""
|
326 |
-
)
|
327 |
-
speeches = df["speech_key"].unique()
|
328 |
-
speeches = speeches.tolist()
|
329 |
-
speech = gr.Dropdown(label="Select a Speech", choices=speeches)
|
330 |
-
# create a dropdown to select a speech from a president
|
331 |
-
run_summarization = gr.Button(value="Summarize")
|
332 |
-
fin_speech = gr.Textbox(label="Summarized Speech", type="text", lines=10)
|
333 |
-
run_summarization.click(
|
334 |
-
streaming, inputs=[speech, df_state], outputs=[fin_speech]
|
335 |
-
)
|
336 |
-
|
337 |
demo.launch()
|
|
|
1 |
+
# pylint: disable=no-member
|
2 |
+
# pylint: disable=not-an-iterable
|
3 |
from collections import Counter
|
4 |
import math
|
5 |
import os
|
|
|
172 |
messages=[
|
173 |
{
|
174 |
"role": "system",
|
175 |
+
"content": "You are a political scholar with a deep knowledge of State of the Union addresses. You are tasked with summarizing a speech from a given president. The content should be structured like you were writing a short essay. The goal is to provide a concise summary of the speech with the proper historical and political context. Where applicable, directly quote the speech.",
|
176 |
},
|
177 |
{
|
178 |
"role": "user",
|
179 |
+
"content": f"The following speech is a State of the Union address from {speech_info[0]} on {speech_info[1]}. Summarize it in 500 words: {speech}",
|
180 |
},
|
181 |
],
|
182 |
+
max_tokens=1200,
|
183 |
stream=True,
|
184 |
+
temperature=0.5,
|
185 |
):
|
186 |
# yield message.choices[0].delta.content
|
187 |
# print(message)
|
|
|
206 |
"In addition to analyzing the content, this space also leverages the [Qwen/2.5-72B-Instruct](https://deepinfra.com/Qwen/Qwen2.5-72B-Instruct) model to summarize a speech. The model is tasked with providing a concise summary of a speech from a given president. To get a summary, go to the 'Summarize a Speech' tab."
|
207 |
)
|
208 |
|
209 |
+
with gr.Tab(label="Summarize a Speech"):
|
210 |
+
gr.Markdown("## Summarize a Speech")
|
211 |
+
gr.Markdown(
|
212 |
+
"""
|
213 |
+
Context is king; get a summary of a State of the Union now that you've seen a bit more. Use the dropdown to select a speech from a president and click the button to summarize the speech. [Qwen/2.5-72B-Instruct](https://deepinfra.com/Qwen/Qwen2.5-72B-Instruct) will provide a concise summary of the speech with the proper historical and political context.
|
214 |
+
"""
|
215 |
+
)
|
216 |
+
speeches = df["speech_key"].unique()
|
217 |
+
speeches = speeches.tolist()
|
218 |
+
speech = gr.Dropdown(label="Select a Speech", choices=speeches)
|
219 |
+
# create a dropdown to select a speech from a president
|
220 |
+
run_summarization = gr.Button(value="Summarize")
|
221 |
+
fin_speech = gr.Textbox(label="Summarized Speech", type="text", lines=10)
|
222 |
+
run_summarization.click(
|
223 |
+
streaming, inputs=[speech, df_state], outputs=[fin_speech]
|
224 |
+
)
|
225 |
+
|
226 |
with gr.Tab(label="Speech Data"):
|
227 |
# Basic line chart showing the total number of words in each address
|
228 |
gr.Markdown(
|
|
|
337 |
# show a line chart of word count and ARI for a selected president
|
338 |
gr.Plot(plotly_word_and_ari, inputs=[president, df_state])
|
339 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
demo.launch()
|
poetry.lock
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# This file is automatically @generated by Poetry 1.8.
|
2 |
|
3 |
[[package]]
|
4 |
name = "aiofiles"
|
@@ -732,19 +732,19 @@ tqdm = ["tqdm"]
|
|
732 |
|
733 |
[[package]]
|
734 |
name = "gradio"
|
735 |
-
version = "4.
|
736 |
description = "Python library for easily interacting with trained machine learning models"
|
737 |
optional = false
|
738 |
python-versions = ">=3.8"
|
739 |
files = [
|
740 |
-
{file = "gradio-4.
|
741 |
-
{file = "gradio-4.
|
742 |
]
|
743 |
|
744 |
[package.dependencies]
|
745 |
aiofiles = ">=22.0,<24.0"
|
746 |
anyio = ">=3.0,<5.0"
|
747 |
-
fastapi = "
|
748 |
ffmpy = "*"
|
749 |
gradio-client = "1.3.0"
|
750 |
httpx = ">=0.24.1"
|
|
|
1 |
+
# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand.
|
2 |
|
3 |
[[package]]
|
4 |
name = "aiofiles"
|
|
|
732 |
|
733 |
[[package]]
|
734 |
name = "gradio"
|
735 |
+
version = "4.44.1"
|
736 |
description = "Python library for easily interacting with trained machine learning models"
|
737 |
optional = false
|
738 |
python-versions = ">=3.8"
|
739 |
files = [
|
740 |
+
{file = "gradio-4.44.1-py3-none-any.whl", hash = "sha256:c908850c638e4a176b22f95a758ce6a63ffbc2a7a5a74b23186ceeeedc23f4d9"},
|
741 |
+
{file = "gradio-4.44.1.tar.gz", hash = "sha256:a68a52498ac6b63f8864ef84bf7866a70e7d07ebe913edf921e1d2a3708ad5ae"},
|
742 |
]
|
743 |
|
744 |
[package.dependencies]
|
745 |
aiofiles = ">=22.0,<24.0"
|
746 |
anyio = ">=3.0,<5.0"
|
747 |
+
fastapi = "<1.0"
|
748 |
ffmpy = "*"
|
749 |
gradio-client = "1.3.0"
|
750 |
httpx = ">=0.24.1"
|