peterciank commited on
Commit
c5068e2
·
verified ·
1 Parent(s): 6755798

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ import requests
4
+
5
+
6
+ # Set up Hugging Face API details
7
+ #token=os.getenv("HF_TOKEN", None)
8
+ st.write("Hello")
9
+ #st.write(token)
10
+ '''
11
+ headers = {"Authorization": f"Bearer {token}"}
12
+ API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
13
+ # Function to query the Hugging Face model
14
+ def query(payload):
15
+ response = requests.post(API_URL, headers=headers, json=payload)
16
+ return response.json()
17
+ # Streamlit UI
18
+ st.title("Chat App with Hugging Face")
19
+ user_input = st.text_input("You:", "")
20
+ if st.button("Send"):
21
+ if user_input.strip() != "":
22
+ # Query Hugging Face model
23
+ data = query({"inputs": user_input, "parameters": {"do_sample": False}})
24
+
25
+ # Display response
26
+ if data and "summary_text" in data[0]:
27
+ st.text_area("Bot:", value=data[0]["summary_text"], height=150)
28
+ else:
29
+ st.error("No response from the model")
30
+ '''