Spaces:
Sleeping
Sleeping
File size: 2,472 Bytes
c5068e2 9cf9aa7 c5068e2 a6212b3 fc807d5 c5068e2 a6212b3 c202d64 1a62c2c fc807d5 9cf9aa7 1a62c2c 55684b3 fc807d5 9cf9aa7 1a62c2c c202d64 1a62c2c f05eb07 1a62c2c d5e9d54 1a62c2c d5e9d54 1a62c2c b7c86f6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | import os
import streamlit as st
import requests
# Set up Hugging Face API details
token = os.getenv("HF_TOKEN", None)
headers = {"Authorization": f"Bearer {token}"}
API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
# Title and description for this particular project
st.title("Large Language Model using Inference API")
st.write("This project will show how Inference API and Bart LLM uses text summarization.")
st.write("It is very simple implementation, and other models can be used.")
# Function to query the Hugging Face model
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
# Input textbox to introduce prompt
user_input = st.text_input("You:", "")
# Submit button to run the inference API
if st.button("Send"):
if user_input.strip() != "":
# Query Hugging Face model
data = query({"inputs": user_input, "parameters": {"do_sample": False}})
# Display response
if data and "summary_text" in data[0]:
st.text_area("Bot:", value=data[0]["summary_text"], height=150)
else:
st.error("No response from the model")
# Model selection
model = st.radio(
"Model",
[
"OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5",
"OpenAssistant/oasst-sft-1-pythia-12b",
"google/flan-t5-xxl",
"google/flan-ul2",
"bigscience/bloom",
"bigscience/bloomz",
"EleutherAI/gpt-neox-20b",
]
)
# Input textbox
input_text = st.text_input(label="Type an input and press Enter", placeholder="What is Deep Learning?")
# Parameters
with st.expander("Parameters", expanded=False):
typical_p = st.slider("Typical P mass", min_value=0.0, max_value=1.0, value=0.2, step=0.05)
top_p = st.slider("Top-p (nucleus sampling)", min_value=0.0, max_value=1.0, value=0.25, step=0.05)
temperature = st.slider("Temperature", min_value=0.0, max_value=5.0, value=0.6, step=0.1)
top_k = st.slider("Top-k", min_value=1, max_value=50, value=50, step=1)
repetition_penalty = st.slider("Repetition Penalty", min_value=0.1, max_value=3.0, value=1.03, step=0.01)
watermark = st.checkbox("Text watermarking", value=False)
# Submit button
if st.button("Submit"):
# Perform prediction
predict(model, input_text, typical_p, top_p, temperature, top_k, repetition_penalty, watermark)
'''
# Reset button
if st.button("Reset"):
input_text = ""
''' |