sachitksh123 commited on
Commit
76586ef
·
verified ·
1 Parent(s): 36cc6c4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ from transformers import pipeline
4
+ import urllib3
5
+
6
+ # Disable warnings
7
+ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
8
+
9
+ # Create a custom session
10
+ session = requests.Session()
11
+ session.verify = False # Disable SSL verification
12
+
13
+ # Set up the text generation pipeline
14
+ pipe = pipeline("text-generation", model="meta-llama/Llama-3.1-8B-Instruct", use_auth_token=True, request_session=session)
15
+
16
+ # Streamlit application
17
+ st.title("Text Generation with Hugging Face")
18
+
19
+ # User input
20
+ user_input = st.text_input("You: ", "Who are you?")
21
+
22
+ if st.button("Generate Response"):
23
+ if user_input:
24
+ messages = [{"role": "user", "content": user_input}]
25
+ response = pipe(messages)
26
+ generated_text = response[0]['generated_text'] # Adjust according to the response format
27
+ st.text_area("Bot:", generated_text, height=200)
28
+ else:
29
+ st.warning("Please enter a message.")