|
import streamlit as st |
|
import requests |
|
import os |
|
|
|
|
|
API_TOKEN = os.getenv('API_TOKEN', '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') |
|
API_URL = 'https://api-inference.huggingface.co/models/gpt2' |
|
|
|
headers = { |
|
"Authorization": f"Bearer {API_TOKEN}" |
|
} |
|
|
|
|
|
def query(prompt): |
|
payload = {"inputs": prompt} |
|
response = requests.post(API_URL, headers=headers, json=payload) |
|
return response.json() |
|
|
|
|
|
st.title("AI Text Generation with Hugging Face") |
|
|
|
|
|
user_input = st.text_area("Enter a prompt:", "Once upon a time") |
|
|
|
|
|
if st.button("Generate Text"): |
|
|
|
response = query(user_input) |
|
generated_text = response[0]['generated_text'] |
|
st.write(generated_text) |
|
|