Spaces:
Runtime error
Runtime error
PRANJAL KAR
commited on
Commit
·
6e143c5
1
Parent(s):
e90a2ef
Initail Commit
Browse files- Dockerfile +23 -0
- app.py +37 -0
- requirements.txt +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use an official Python runtime as the base image
|
| 2 |
+
FROM python:3.8-slim
|
| 3 |
+
|
| 4 |
+
# Set the working directory in the container
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy the local code and requirements.txt to the container
|
| 8 |
+
COPY . /app/
|
| 9 |
+
|
| 10 |
+
# Install necessary Python packages from requirements.txt
|
| 11 |
+
RUN pip install --upgrade pip && \
|
| 12 |
+
pip install -r requirements.txt
|
| 13 |
+
|
| 14 |
+
# Make port 7860 available to the world outside this container (default port for Gradio)
|
| 15 |
+
EXPOSE 7860
|
| 16 |
+
|
| 17 |
+
# Define an environment variable (Optional)
|
| 18 |
+
# This can be used to set Gradio server name, port, etc.
|
| 19 |
+
# ENV GRADIO_SERVER_NAME 0.0.0.0
|
| 20 |
+
# ENV GRADIO_SERVER_PORT 7860
|
| 21 |
+
|
| 22 |
+
# Run your script when the container launches
|
| 23 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import transformers
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
model = "tiiuae/falcon-180b-chat"
|
| 7 |
+
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model)
|
| 9 |
+
pipeline = transformers.pipeline(
|
| 10 |
+
"text-generation",
|
| 11 |
+
model=model,
|
| 12 |
+
tokenizer=tokenizer,
|
| 13 |
+
torch_dtype=torch.bfloat16,
|
| 14 |
+
trust_remote_code=True,
|
| 15 |
+
device_map="auto",
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
def generate_headlines(topic):
|
| 19 |
+
sequences = pipeline(
|
| 20 |
+
f"Create at most 5 headlines that highlight {topic}. The headlines should be concise, attention-grabbing, and suitable for use in a news video.",
|
| 21 |
+
max_length=200,
|
| 22 |
+
do_sample=True,
|
| 23 |
+
top_k=10,
|
| 24 |
+
num_return_sequences=5,
|
| 25 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 26 |
+
)
|
| 27 |
+
headlines = [seq['generated_text'] for seq in sequences]
|
| 28 |
+
return "\n".join(headlines)
|
| 29 |
+
|
| 30 |
+
iface = gr.Interface(
|
| 31 |
+
fn=generate_headlines,
|
| 32 |
+
inputs=gr.inputs.Textbox(placeholder="Enter the topic"),
|
| 33 |
+
outputs="text",
|
| 34 |
+
examples=[["Climate Change"], ["AI Innovations"], ["Space Exploration"]]
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|