Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
import torch
|
3 |
from threading import Thread
|
4 |
from typing import Iterator
|
@@ -56,6 +57,18 @@ def make_prompt(entry):
|
|
56 |
return f"### Human: Don't repeat the assesments, limit to 500 words {entry} ### Assistant:"
|
57 |
# f"TELL A STORY, RELATE TO COMPUTER SCIENCE, INCLUDE ASSESMENTS. MAKE IT REALISTIC AND AROUND 800 WORDS: {entry}"
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
# Gradio Function
|
60 |
@spaces.GPU
|
61 |
def generate(
|
@@ -94,7 +107,8 @@ def generate(
|
|
94 |
|
95 |
outputs = []
|
96 |
for text in streamer:
|
97 |
-
|
|
|
98 |
yield "".join(outputs)
|
99 |
final_story = "".join(outputs)
|
100 |
try:
|
|
|
1 |
import os
|
2 |
+
import re
|
3 |
import torch
|
4 |
from threading import Thread
|
5 |
from typing import Iterator
|
|
|
57 |
return f"### Human: Don't repeat the assesments, limit to 500 words {entry} ### Assistant:"
|
58 |
# f"TELL A STORY, RELATE TO COMPUTER SCIENCE, INCLUDE ASSESMENTS. MAKE IT REALISTIC AND AROUND 800 WORDS: {entry}"
|
59 |
|
60 |
+
def process_text(text):
|
61 |
+
# Bold specific bracketed phrases
|
62 |
+
text = re.sub(r'\[(assessment.*?)]', r'**[\1]**', text, flags=re.IGNORECASE)
|
63 |
+
text = re.sub(r'\[(answer.*?)]', r'**[\1]**', text, flags=re.IGNORECASE)
|
64 |
+
|
65 |
+
# Remove all other bracketed content
|
66 |
+
text = re.sub(r'\[.*?\]', '', text) # Removes any text in square brackets
|
67 |
+
text = re.sub(r'\(.*?\)', '', text) # Removes any text in round brackets
|
68 |
+
text = re.sub(r'\{.*?\}', '', text) # Removes any text in curly brackets
|
69 |
+
|
70 |
+
return text
|
71 |
+
|
72 |
# Gradio Function
|
73 |
@spaces.GPU
|
74 |
def generate(
|
|
|
107 |
|
108 |
outputs = []
|
109 |
for text in streamer:
|
110 |
+
processed_text = process_text(text)
|
111 |
+
outputs.append(processed_text)
|
112 |
yield "".join(outputs)
|
113 |
final_story = "".join(outputs)
|
114 |
try:
|