Caseyishere commited on
Commit
133d782
·
verified ·
1 Parent(s): 2efe8d0

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -0
app.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import torch
4
+ import numpy as np
5
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
6
+
7
+ # Load the model and tokenizer from Hugging Face
8
+ model = AutoModelForSequenceClassification.from_pretrained("Caseyishere/StoryCraft", num_labels=5)
9
+ tokenizer = AutoTokenizer.from_pretrained("Caseyishere/StoryCraft")
10
+
11
+ # Streamlit app interface
12
+ st.set_page_config(page_title="Story Craft", page_icon="🍽️", layout="centered")
13
+
14
+ # Set page title and styles
15
+ st.title("🍽️ Welcome to Story Craft 🍽️")
16
+ st.markdown("""
17
+ <style>
18
+ .big-font {
19
+ font-size:24px !important;
20
+ font-weight:bold;
21
+ }
22
+ .highlight {
23
+ color: #FF4B4B;
24
+ }
25
+ .divider {
26
+ border-top: 2px solid #bbb;
27
+ margin: 20px 0;
28
+ }
29
+ .menu {
30
+ font-size:18px !important;
31
+ line-height: 1.8;
32
+ font-family: 'Arial', sans-serif;
33
+ }
34
+ </style>
35
+ """, unsafe_allow_html=True)
36
+
37
+ # Get user input
38
+ user_input = st.text_input("Please tell us what you like today:")
39
+
40
+ if user_input:
41
+ # Preprocess the input using the tokenizer
42
+ inputs = tokenizer(user_input, padding=True, truncation=True, return_tensors='pt')
43
+
44
+ # Get predictions from the model
45
+ outputs = model(**inputs)
46
+ predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
47
+ predictions = predictions.cpu().detach().numpy()
48
+
49
+ # Get the predicted label
50
+ predicted_label = np.argmax(predictions)
51
+
52
+ # Display the predicted label with its corresponding sentiment
53
+ label_map = {0: "Negative", 1: "Neutral", 2: "Positive"}
54
+
55
+ # Display the predicted label and corresponding sentiment
56
+ st.write(f"Predicted label is {predicted_label} ({label_map.get(predicted_label, 'Unknown')} Sentence)")
57
+
58
+ # Generate response based on predicted label
59
+ responses = {
60
+ 0: '''**Appetizer**: Escargots: Snails cooked in garlic butter with herbs
61
+ **Main Course**: Coq au vin: Chicken braised in red wine with mushrooms and onions
62
+ **Side Dish**: Pommes frites: French fries
63
+ **Dessert**: Crème brûlée: Custard topped with caramelized sugar
64
+ **Beverage**: Bordeaux: A red wine from the Bordeaux region of France
65
+ **Cheese Course**: Fromage à raclette: Melted cheese served with bread, potatoes, and pickles''',
66
+ 1: '''**Appetizer**: Spätzle: Swabian egg noodles with cheese
67
+ **Main Course**: Wiener schnitzel: Breaded veal cutlet
68
+ **Side Dish**: Sauerkraut: Fermented cabbage
69
+ **Dessert**: Schwarzwälder Kirschtorte: Black Forest cake
70
+ **Beverage**: Kölsch: A light, golden ale from Cologne
71
+ **Cheese Course**: Käsekuchen: German cheesecake''',
72
+ 2: '''**Appetizer**: Creamy Spinach and Artichoke Dip with tortilla chips
73
+ **Main Course**: Ribeye Steak cooked to your desired temperature (medium-rare, medium, well-done)
74
+ **Side Dish**: Baked Potato topped with butter, sour cream, and bacon bits
75
+ **Dessert**: Chocolate Lava Cake with vanilla ice cream
76
+ **Beverage**: Red Wine (ask your server for a recommendation based on your preferences)
77
+ **Salad**: Caesar Salad with romaine lettuce, croutons, Parmesan cheese, and Caesar dressing
78
+ **Soup**: French Onion Soup with caramelized onions, Gruyère cheese, and croutons''',
79
+ 3: "Oops! Something went wrong!"
80
+ }
81
+
82
+ # Display the response based on the predicted label
83
+ st.markdown('<div class="divider"></div>', unsafe_allow_html=True)
84
+ st.markdown(f'<div class="big-font highlight">Here is your curated menu based on your input:</div>', unsafe_allow_html=True)
85
+
86
+ # Correcting the misplaced closing parenthesis
87
+ st.write(responses.get(predicted_label, "I'm not sure what you're asking for."))
88
+
89
+ # Add a separator
90
+ st.markdown('<div class="divider"></div>', unsafe_allow_html=True)