forked from tylerprogramming/ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added the huggingface code and updated reddit integration with autogen
- Loading branch information
1 parent
5015af5
commit 27cdabd
Showing
4 changed files
with
157 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import streamlit as st | ||
import json | ||
import reddit | ||
|
||
st.title = "Reddit App" | ||
|
||
with st.container(border=True): | ||
mode = st.radio( | ||
"Choose a mode", | ||
[":rainbow[Random]", "***Specific Subreddit***"], | ||
captions=["Laugh out loud.", "Get the popcorn."] | ||
) | ||
|
||
number = st.slider("Pick a number", 1, 10) | ||
|
||
response = "" | ||
|
||
if mode == ":rainbow[Random]": | ||
prompt = f"Get me {number} random subreddit(s)!" | ||
submit = st.button(prompt) | ||
|
||
if submit: | ||
response = reddit.start_chat(prompt) | ||
|
||
if mode == "***Specific Subreddit***": | ||
input = st.text_input("") | ||
submit = st.button(f"Give me content!") | ||
prompt = f"Give me {number} subreddit posts on: {input}" | ||
|
||
if submit: | ||
response = reddit.start_chat(prompt) | ||
|
||
with st.spinner('Wait for it...'): | ||
if response: | ||
st.success('Done!') | ||
response = json.loads(response) | ||
st.divider() | ||
|
||
for data in response: | ||
# Extracting 'content' | ||
content = data["content"] | ||
|
||
# Extracting 'meta_data' | ||
meta_data = data["meta_data"] | ||
|
||
# Extracting each property from 'meta_data' | ||
post_subreddit = meta_data["subreddit"] | ||
post_category = meta_data["category"] | ||
post_title = meta_data["title"] | ||
post_score = meta_data["score"] | ||
post_url = meta_data["url"] | ||
post_author = meta_data["author"] | ||
|
||
st.header("Metadata") | ||
st.divider() | ||
st.markdown('**Subreddit**: ' + post_subreddit) | ||
st.markdown('**Category**: ' + post_category) | ||
st.markdown('**Title**: ' + post_title) | ||
st.markdown('**URL**: ' + post_url) | ||
st.markdown('**Author**: ' + post_author) | ||
|
||
st.header("Content") | ||
st.divider() | ||
st.write(content) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import requests | ||
import pprint as p | ||
|
||
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct" | ||
headers = {"Authorization": "Bearer hf_xxxx"} | ||
|
||
|
||
def query(payload): | ||
response = requests.post(API_URL, headers=headers, json=payload) | ||
return response.json() | ||
|
||
|
||
output = query({ | ||
"inputs": "Can you give me a sample python function for binary search.", | ||
}) | ||
|
||
p.pprint(output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import requests | ||
|
||
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0" | ||
headers = {"Authorization": "Bearer hf_xxxx"} | ||
|
||
|
||
def query(payload): | ||
response = requests.post(API_URL, headers=headers, json=payload) | ||
return response.content | ||
|
||
|
||
image_bytes = query({ | ||
"inputs": "Astronaut riding a horse", | ||
}) | ||
# You can access the image with PIL.Image for example | ||
import io | ||
from PIL import Image | ||
|
||
image = Image.open(io.BytesIO(image_bytes)) | ||
image.save("tester.png") |