File size: 1,123 Bytes
76586ef
 
 
 
9716484
76586ef
 
 
 
 
 
 
 
9716484
e9d7be2
60ef490
 
8f76f02
60ef490
76586ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
import streamlit as st
import requests
from transformers import pipeline
import urllib3
import os

# Disable warnings
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

# Create a custom session
session = requests.Session()
session.verify = False  # Disable SSL verification

# Load the token from Hugging Face secrets
HUGGINGFACE_TOKEN = os.environ.get("hf_token")  # Set the default to empty if not found

# Set up the text generation pipeline with the token
pipe = pipeline("text-generation", model="mistralai/Mistral-7B-v0.1", 
                use_auth_token=HUGGINGFACE_TOKEN, request_session=session)

# Streamlit application
st.title("Text Generation with Hugging Face")

# User input
user_input = st.text_input("You: ", "Who are you?")

if st.button("Generate Response"):
    if user_input:
        messages = [{"role": "user", "content": user_input}]
        response = pipe(messages)
        generated_text = response[0]['generated_text']  # Adjust according to the response format
        st.text_area("Bot:", generated_text, height=200)
    else:
        st.warning("Please enter a message.")