Spaces:
Runtime error
Runtime error
Andyrasika
commited on
Commit
·
327d5b5
1
Parent(s):
37c8d9e
Update app.py
Browse files
app.py
CHANGED
@@ -6,22 +6,6 @@ import pyspark.sql.functions as F
|
|
6 |
from llama_cpp import Llama
|
7 |
from loguru import logger # Import the logger from loguru
|
8 |
|
9 |
-
# Create the models directory
|
10 |
-
!mkdir -p ./models
|
11 |
-
|
12 |
-
# Download the Llama model files
|
13 |
-
!wget -O ./models/llama-2-7b-chat.ggmlv3.q8_0.bin https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/resolve/main/llama-2-7b-chat.ggmlv3.q8_0.bin
|
14 |
-
!wget -O ./models/llama-2-7b-chat.ggmlv3.q2_K.bin https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/resolve/main/llama-2-7b-chat.ggmlv3.q2_K.bin
|
15 |
-
|
16 |
-
# download "War and Peace" from Project Gutenberg
|
17 |
-
!mkdir -p ./data
|
18 |
-
!curl "https://gutenberg.org/cache/epub/2600/pg2600.txt" -o ./data/war_and_peace.txt
|
19 |
-
|
20 |
-
|
21 |
-
# Define the Llama models
|
22 |
-
MODEL_Q8_0 = Llama(model_path="./models/llama-2-7b-chat.ggmlv3.q8_0.bin", n_ctx=8192, n_batch=512)
|
23 |
-
MODEL_Q2_K = Llama(model_path="./models/llama-2-7b-chat.ggmlv3.q2_K.bin", n_ctx=8192, n_batch=512)
|
24 |
-
|
25 |
# Function to read the text file and create Spark DataFrame
|
26 |
def create_spark_dataframe(text):
|
27 |
# Get list of chapter strings
|
@@ -34,6 +18,15 @@ def create_spark_dataframe(text):
|
|
34 |
|
35 |
return df
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
# Function to summarize a chapter using the selected model
|
38 |
def llama2_summarize(chapter_text, model_version):
|
39 |
# Choose the model based on the model_version parameter
|
@@ -74,34 +67,19 @@ def llama2_summarize(chapter_text, model_version):
|
|
74 |
|
75 |
return summary
|
76 |
|
77 |
-
# Read the "War and Peace" text file and create Spark DataFrame
|
78 |
-
with open('/content/data/war_and_peace.txt', 'r') as file:
|
79 |
-
text = file.read()
|
80 |
-
df_chapters = create_spark_dataframe(text)
|
81 |
-
|
82 |
-
# Create summaries via Spark
|
83 |
-
summaries = (df_chapters
|
84 |
-
.limit(1)
|
85 |
-
.groupby('chapter')
|
86 |
-
.applyInPandas(llama2_summarize, schema='summary string, chapter int')
|
87 |
-
.show(vertical=True, truncate=False)
|
88 |
-
)
|
89 |
-
|
90 |
-
# Prompt for the file
|
91 |
-
file_path = gr.inputs.File(label="Upload 'War and Peace' text file")
|
92 |
-
|
93 |
-
# Choose the model version
|
94 |
-
model_version = gr.inputs.Radio(["q8_0", "q2_K"], label="Choose Model Version")
|
95 |
-
|
96 |
# Define the Gradio interface
|
97 |
iface = gr.Interface(
|
98 |
fn=llama2_summarize,
|
99 |
-
inputs=[
|
|
|
|
|
|
|
100 |
outputs="text", # Summary text
|
101 |
live=False,
|
102 |
capture_session=True,
|
103 |
title="Llama2 Chapter Summarizer",
|
104 |
-
description="Upload
|
105 |
)
|
106 |
|
107 |
-
|
|
|
|
6 |
from llama_cpp import Llama
|
7 |
from loguru import logger # Import the logger from loguru
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# Function to read the text file and create Spark DataFrame
|
10 |
def create_spark_dataframe(text):
|
11 |
# Get list of chapter strings
|
|
|
18 |
|
19 |
return df
|
20 |
|
21 |
+
# Read the "War and Peace" text file and create Spark DataFrame
|
22 |
+
with open('/content/data/war_and_peace.txt', 'r') as file:
|
23 |
+
text = file.read()
|
24 |
+
df_chapters = create_spark_dataframe(text)
|
25 |
+
|
26 |
+
# Define the Llama models
|
27 |
+
MODEL_Q8_0 = Llama(model_path="./models/llama-2-7b-chat.ggmlv3.q8_0.bin", n_ctx=8192, n_batch=512)
|
28 |
+
MODEL_Q2_K = Llama(model_path="./models/llama-2-7b-chat.ggmlv3.q2_K.bin", n_ctx=8192, n_batch=512)
|
29 |
+
|
30 |
# Function to summarize a chapter using the selected model
|
31 |
def llama2_summarize(chapter_text, model_version):
|
32 |
# Choose the model based on the model_version parameter
|
|
|
67 |
|
68 |
return summary
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
# Define the Gradio interface
|
71 |
iface = gr.Interface(
|
72 |
fn=llama2_summarize,
|
73 |
+
inputs=[
|
74 |
+
gr.inputs.File(label="Upload Text File"),
|
75 |
+
"text",
|
76 |
+
], # chapter_text, model_version
|
77 |
outputs="text", # Summary text
|
78 |
live=False,
|
79 |
capture_session=True,
|
80 |
title="Llama2 Chapter Summarizer",
|
81 |
+
description="Upload the text file or enter the chapter text and model version ('q8_0' or 'q2_K') to get a summarized sentence.",
|
82 |
)
|
83 |
|
84 |
+
if __name__ == "__main__":
|
85 |
+
iface.launch();
|