Spaces:
Runtime error
Runtime error
Create sample.py
Browse files
sample.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
# Get the token from environment variables
|
| 6 |
+
# token = os.getenv("HUGGINGFACE_TOKEN")
|
| 7 |
+
# if token is None:
|
| 8 |
+
# raise ValueError("Hugging Face token is not set in the environment variables.")
|
| 9 |
+
|
| 10 |
+
# Load the model from the Hugging Face Model Hub with authentication
|
| 11 |
+
generator = pipeline('text-generation', model='your-model-name', use_auth_token=token)
|
| 12 |
+
|
| 13 |
+
# Define the prediction function
|
| 14 |
+
def generate_text(prompt):
|
| 15 |
+
result = generator(prompt, max_length=50)
|
| 16 |
+
return result[0]['generated_text']
|
| 17 |
+
|
| 18 |
+
# Create the Gradio interface
|
| 19 |
+
iface = gr.Interface(fn=generate_text, inputs="text", outputs="text")
|
| 20 |
+
|
| 21 |
+
# Launch the app
|
| 22 |
+
iface.launch()
|