Spaces:
Running
Running
Lucasstranger1
commited on
Commit
•
244ff0b
1
Parent(s):
55dbef8
update
Browse files
app.py
CHANGED
@@ -27,11 +27,39 @@ def query(filename):
|
|
27 |
# Function to generate a joke or uplifting text based on the mood
|
28 |
def generate_text_based_on_mood(emotion):
|
29 |
try:
|
30 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
generator = pipeline('text-generation', model='EleutherAI/gpt-neo-125M')
|
32 |
-
prompt = f"
|
33 |
response = generator(prompt, max_length=50, num_return_sequences=1)
|
34 |
return response[0]['generated_text']
|
|
|
35 |
except Exception as e:
|
36 |
st.error(f"Error generating text: {e}")
|
37 |
return "Sorry, I couldn't come up with a joke at this moment."
|
|
|
27 |
# Function to generate a joke or uplifting text based on the mood
|
28 |
def generate_text_based_on_mood(emotion):
|
29 |
try:
|
30 |
+
# Predefined jokes for different emotions
|
31 |
+
jokes = {
|
32 |
+
"happy": [
|
33 |
+
"Why did the scarecrow win an award? Because he was outstanding in his field!",
|
34 |
+
"What do you call fake spaghetti? An impasta!"
|
35 |
+
],
|
36 |
+
"sad": [
|
37 |
+
"Why don’t scientists trust atoms? Because they make up everything!",
|
38 |
+
"Why did the bicycle fall over? Because it was two-tired."
|
39 |
+
],
|
40 |
+
"angry": [
|
41 |
+
"Why did the tomato turn red? Because it saw the salad dressing!",
|
42 |
+
"What did one angry man say to the other? Nothing, he just threw a rock!"
|
43 |
+
],
|
44 |
+
"surprised": [
|
45 |
+
"Did you hear about the claustrophobic astronaut? He just needed a little space!",
|
46 |
+
"Why don’t skeletons fight each other? They don’t have the guts."
|
47 |
+
],
|
48 |
+
"neutral": [
|
49 |
+
"What do you call cheese that isn't yours? Nacho cheese!"
|
50 |
+
]
|
51 |
+
}
|
52 |
+
|
53 |
+
# Use predefined jokes if available
|
54 |
+
if emotion in jokes:
|
55 |
+
return jokes[emotion][0] # Return the first joke for simplicity
|
56 |
+
|
57 |
+
# If no predefined joke, use GPT-Neo
|
58 |
generator = pipeline('text-generation', model='EleutherAI/gpt-neo-125M')
|
59 |
+
prompt = f"Generate a light-hearted joke for someone who is feeling {emotion}."
|
60 |
response = generator(prompt, max_length=50, num_return_sequences=1)
|
61 |
return response[0]['generated_text']
|
62 |
+
|
63 |
except Exception as e:
|
64 |
st.error(f"Error generating text: {e}")
|
65 |
return "Sorry, I couldn't come up with a joke at this moment."
|