File size: 650 Bytes
61245a6
 
bb30d4c
 
61245a6
24a48da
bb30d4c
 
 
24a48da
61245a6
bb30d4c
 
 
 
61245a6
bb30d4c
 
 
 
61245a6
 
 
 
 
 
bb30d4c
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import streamlit as st
from transformers import pipeline
import subprocess
import sys


# Ensure PyTorch is installed
def install_pytorch():
    subprocess.check_call([sys.executable, "-m", "pip", "install", "torch"])


try:
    import torch
except ImportError:
    install_pytorch()

st.title("Hugging Face Model Demo")


@st.cache_resource
def load_model():
    return pipeline("text-generation", model="klyang/MentaLLaMA-chat-7B")


model = load_model()

user_input = st.text_input("Enter your text:")
if user_input:
    with st.spinner("Generating response..."):
        result = model(user_input)
        st.success(result[0]["generated_text"])