Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -95,19 +95,21 @@ body, input, button, textarea, label {
|
|
95 |
}
|
96 |
"""
|
97 |
|
98 |
-
|
|
|
|
|
|
|
|
|
99 |
@spaces.GPU
|
100 |
def generate(
|
101 |
message: str,
|
102 |
chat_history: list[tuple[str, str]],
|
103 |
max_new_tokens: int = DEFAULT_MAX_NEW_TOKENS,
|
104 |
-
temperature: float = 0.
|
105 |
top_p: float = 0.7,
|
106 |
-
top_k: int =
|
107 |
repetition_penalty: float = 1.0,
|
108 |
) -> Iterator[str]:
|
109 |
-
logging.debug("Starting chat generation with message: %s", message)
|
110 |
-
|
111 |
conversation = []
|
112 |
for user, assistant in chat_history:
|
113 |
conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
@@ -141,10 +143,17 @@ def generate(
|
|
141 |
yield output
|
142 |
|
143 |
final_story = "".join(outputs)
|
144 |
-
|
|
|
|
|
145 |
return f"{final_story}\n\n"
|
146 |
|
147 |
|
|
|
|
|
|
|
|
|
|
|
148 |
chat_interface = gr.ChatInterface(
|
149 |
fn=generate,
|
150 |
fill_height=True,
|
|
|
95 |
}
|
96 |
"""
|
97 |
|
98 |
+
def process_text(text):
|
99 |
+
text = re.sub(r'\[assessment;[^\]]*\]', '', text, flags=re.DOTALL)
|
100 |
+
text = re.sub(r'\[.*?\]', '', text, flags=re.DOTALL)
|
101 |
+
return text
|
102 |
+
|
103 |
@spaces.GPU
|
104 |
def generate(
|
105 |
message: str,
|
106 |
chat_history: list[tuple[str, str]],
|
107 |
max_new_tokens: int = DEFAULT_MAX_NEW_TOKENS,
|
108 |
+
temperature: float = 0.8,
|
109 |
top_p: float = 0.7,
|
110 |
+
top_k: int = 30,
|
111 |
repetition_penalty: float = 1.0,
|
112 |
) -> Iterator[str]:
|
|
|
|
|
113 |
conversation = []
|
114 |
for user, assistant in chat_history:
|
115 |
conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
|
|
143 |
yield output
|
144 |
|
145 |
final_story = "".join(outputs)
|
146 |
+
final_story_trimmed = remove_last_sentence(final_story)
|
147 |
+
|
148 |
+
image_url = generate_image(final_story_trimmed)
|
149 |
return f"{final_story}\n\n"
|
150 |
|
151 |
|
152 |
+
def remove_last_sentence(text):
|
153 |
+
# Assuming sentences end with a period followed by space or end of string
|
154 |
+
sentences = re.split(r'(?<=\.)\s', text)
|
155 |
+
return ' '.join(sentences[:-1]) if sentences else text
|
156 |
+
|
157 |
chat_interface = gr.ChatInterface(
|
158 |
fn=generate,
|
159 |
fill_height=True,
|