Spaces:
Runtime error
Runtime error
kz209
commited on
Commit
·
576ef40
1
Parent(s):
5e835e3
update
Browse files- pages/summarization_example.py +12 -10
pages/summarization_example.py
CHANGED
|
@@ -4,8 +4,6 @@ import gradio as gr
|
|
| 4 |
|
| 5 |
from utils.model import Model
|
| 6 |
|
| 7 |
-
model = Model()
|
| 8 |
-
|
| 9 |
load_dotenv()
|
| 10 |
|
| 11 |
examples = {
|
|
@@ -23,19 +21,17 @@ All of that has led to postseason averages of 8.2 points, 7.6 rebounds, 1.4 assi
|
|
| 23 |
Back in Boston, Kidd is going to rely on Lively even more. He'll play close to 30 minutes and reach double-figures in both scoring and rebounding again.""",
|
| 24 |
}
|
| 25 |
|
| 26 |
-
def generate_answer(sources, model_name):
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
summarization: """
|
| 31 |
content = meta_prompt.format(sources=sources)
|
| 32 |
answer = model.gen(content)
|
| 33 |
|
| 34 |
return answer
|
| 35 |
|
| 36 |
-
def process_input(input_text, model_selection):
|
| 37 |
if input_text:
|
| 38 |
-
response = generate_answer(input_text, model_selection)
|
| 39 |
return f"## Original Article:\n\n{input_text}\n\n## Summarization:\n\n{response}"
|
| 40 |
else:
|
| 41 |
return "Please fill the input to generate outputs."
|
|
@@ -51,12 +47,18 @@ def create_summarization_interface():
|
|
| 51 |
example_dropdown = gr.Dropdown(choices=list(examples.keys()), label="Choose an example")
|
| 52 |
model_dropdown = gr.Dropdown(choices=["lmsys/vicuna-7b-v1.5", "tiiuae/falcon-7b-instruct"], label="Choose a model", value="gpt-3.5-turbo")
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
input_text = gr.Textbox(label="Input Text", lines=10, placeholder="Enter text here...")
|
| 55 |
submit_button = gr.Button("✨ Submit ✨")
|
| 56 |
output = gr.Markdown()
|
| 57 |
|
| 58 |
example_dropdown.change(update_input, inputs=[example_dropdown], outputs=[input_text])
|
| 59 |
-
submit_button.click(process_input, inputs=[input_text, model_dropdown], outputs=[output])
|
| 60 |
|
| 61 |
return demo
|
| 62 |
|
|
|
|
| 4 |
|
| 5 |
from utils.model import Model
|
| 6 |
|
|
|
|
|
|
|
| 7 |
load_dotenv()
|
| 8 |
|
| 9 |
examples = {
|
|
|
|
| 21 |
Back in Boston, Kidd is going to rely on Lively even more. He'll play close to 30 minutes and reach double-figures in both scoring and rebounding again.""",
|
| 22 |
}
|
| 23 |
|
| 24 |
+
def generate_answer(sources, model_name, prompt):
|
| 25 |
+
model = Model(model_name)
|
| 26 |
+
meta_prompt = prompt
|
|
|
|
|
|
|
| 27 |
content = meta_prompt.format(sources=sources)
|
| 28 |
answer = model.gen(content)
|
| 29 |
|
| 30 |
return answer
|
| 31 |
|
| 32 |
+
def process_input(input_text, model_selection, prompt):
|
| 33 |
if input_text:
|
| 34 |
+
response = generate_answer(input_text, model_selection, prompt)
|
| 35 |
return f"## Original Article:\n\n{input_text}\n\n## Summarization:\n\n{response}"
|
| 36 |
else:
|
| 37 |
return "Please fill the input to generate outputs."
|
|
|
|
| 47 |
example_dropdown = gr.Dropdown(choices=list(examples.keys()), label="Choose an example")
|
| 48 |
model_dropdown = gr.Dropdown(choices=["lmsys/vicuna-7b-v1.5", "tiiuae/falcon-7b-instruct"], label="Choose a model", value="gpt-3.5-turbo")
|
| 49 |
|
| 50 |
+
Template_text = gr.Textbox(value="""{sources}
|
| 51 |
+
|
| 52 |
+
summarization: """, label='Input Prompting Template', lines=10, placeholder='Input your propmts, must include \{sources\}')
|
| 53 |
+
|
| 54 |
+
assert "{sources}" in Template_text, ValueError("No {sources} Found")
|
| 55 |
+
|
| 56 |
input_text = gr.Textbox(label="Input Text", lines=10, placeholder="Enter text here...")
|
| 57 |
submit_button = gr.Button("✨ Submit ✨")
|
| 58 |
output = gr.Markdown()
|
| 59 |
|
| 60 |
example_dropdown.change(update_input, inputs=[example_dropdown], outputs=[input_text])
|
| 61 |
+
submit_button.click(process_input, inputs=[input_text, model_dropdown, Template_text], outputs=[output])
|
| 62 |
|
| 63 |
return demo
|
| 64 |
|