BtB-ExpC's picture
gradio 3.0
2e6e90a verified
raw
history blame contribute delete
990 Bytes
import anthropic
import gradio as gr
import os
# Initialize the Anthropic client
client = anthropic.Anthropic(
api_key=os.environ["ANTHROPIC_API_KEY"]
)
prompt = r"""Summarize the text in bullet points."""
def chatbot(input):
if input:
messages = [
{"role": "user", "content": f"{prompt}\n{input}"}
]
response = client.messages.create(
model="claude-3-haiku-20240307",
max_tokens=1024,
messages=messages
)
reply = response.content[0].text
return reply.lstrip()
# Create the Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# Lil Summarizer")
gr.Markdown("Submit your text to have it summarized")
input_text = gr.Textbox(lines=10, label="Input")
output_text = gr.Textbox(label="Summary")
submit_button = gr.Button("Summarize")
submit_button.click(fn=chatbot, inputs=input_text, outputs=output_text)
demo.launch(share=False)