Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
+
|
5 |
+
api_token = os.environ.get("api_token")
|
6 |
+
API_URL = "https://api-inference.huggingface.co/models/google/gemma-7b"
|
7 |
+
headers = {"Authorization": f"Bearer {api_token}"}
|
8 |
+
st.title("Google Gemma 7B Chat")
|
9 |
+
st.write("New powerful text generation model by Google AI trained on 7B parameters. Enter your message and get response in few seconds!")
|
10 |
+
mainc = st.container(height=600)
|
11 |
+
cont = mainc.container(height=400)
|
12 |
+
prompt = mainc.chat_input(placeholder="Eg. Why astronaut riding a horse is most popular prompt for testing ai models?")
|
13 |
+
|
14 |
+
def query(payload):
|
15 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
16 |
+
return response.json()
|
17 |
+
|
18 |
+
if prompt:
|
19 |
+
if len(prompt) > 8000:
|
20 |
+
errormsg = st.chat_message("Assistant", avatar="⚠")
|
21 |
+
errormsg.markdown(":red[Sorry, prompt can't be longer than 8000 tokens!]")
|
22 |
+
else:
|
23 |
+
output = query({
|
24 |
+
"inputs": prompt,
|
25 |
+
})
|
26 |
+
if output != None:
|
27 |
+
user_msg = st.caht_message("User")
|
28 |
+
user_msg.write(prompt)
|
29 |
+
as_msg = st.chat_message("Assistant")
|
30 |
+
as_msg.write(output)
|