CoolFace
Apppublic

Caseyishere/StoryCraft

sourceHugging Faceupdated 2y agoView on Hugging Face
2likes
app.py91 linesDownload Raw Back to root
1 2import streamlit as st3import torch4import numpy as np5from transformers import AutoTokenizer, AutoModelForSequenceClassification6 7# Load the model and tokenizer from Hugging Face8model = AutoModelForSequenceClassification.from_pretrained("Caseyishere/StoryCraft", num_labels=5)9tokenizer = AutoTokenizer.from_pretrained("Caseyishere/StoryCraft")10 11# Streamlit app interface12st.set_page_config(page_title="Story Craft", page_icon="🍽️", layout="centered")13 14# Set page title and styles15st.title("🍽️ Welcome to Story Craft 🍽️")16st.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 input38user_input = st.text_input("Please tell us what you like today:")39 40if user_input:41    # Preprocess the input using the tokenizer42    inputs = tokenizer(user_input, padding=True, truncation=True, return_tensors='pt')43 44    # Get predictions from the model45    outputs = model(**inputs)46    predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)47    predictions = predictions.cpu().detach().numpy()48 49    # Get the predicted label50    predicted_label = np.argmax(predictions)51 52    # Display the predicted label with its corresponding sentiment53    label_map = {0: "Negative", 1: "Neutral", 2: "Positive"}54 55    # Display the predicted label and corresponding sentiment56    st.write(f"Predicted label is {predicted_label} ({label_map.get(predicted_label, 'Unknown')} Sentence)")57 58    # Generate response based on predicted label59    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 label83    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 parenthesis87    st.write(responses.get(predicted_label, "I'm not sure what you're asking for."))88 89    # Add a separator90    st.markdown('<div class="divider"></div>', unsafe_allow_html=True)91