Skip to content

Commit

Permalink
add audio option
Browse files Browse the repository at this point in the history
  • Loading branch information
VinciGit00 committed Feb 23, 2024
1 parent 8cc04b0 commit c18d018
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 28 deletions.
Binary file added __pycache__/text_to_speech.cpython-311.pyc
Binary file not shown.
Binary file added audio_result.mp3
Binary file not shown.
Binary file modified default.sqlite
Binary file not shown.
62 changes: 35 additions & 27 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import pandas as pd
from task import task
from text_to_speech import text_to_speech

with st.sidebar:
st.write("# Usage Examples")
Expand All @@ -12,6 +13,8 @@
st.write("- Create a voice summary of the webpage")
st.write("## Prompt 3")
st.write("- List me all the images with their visual description")
st.write("## Prompt 4")
st.write("- Read me the summary of the news")

st.title("Scrapegraph-ai")
left_co, cent_co, last_co = st.columns(3)
Expand All @@ -21,7 +24,7 @@
key = st.text_input("API key", type="password")
model = st.radio(
"Select the model",
["gpt-3.5-turbo", "gpt-3.5-turbo-0125", "gpt-4"],
["gpt-3.5-turbo", "gpt-3.5-turbo-0125", "gpt-4", "text-to-speech"],
index=0,
)

Expand All @@ -32,38 +35,43 @@
if not key or not model or not link_to_scrape or not prompt:
st.error("Please fill in all fields.")
else:

st.write("Scraping phase started ...")
(true_lens_result, graph_result) = task(key, link_to_scrape, prompt, model)

left_res, rigth_res = st.columns([1, 1])
if model == "text-to-speech":
res = text_to_speech(key, prompt, link_to_scrape)
st.write(res["answer"])
st.audio(res["audio"])
else:
(true_lens_result, graph_result) = task(key, link_to_scrape, prompt, model)

with left_res:
st.write("# Answer")
st.write(graph_result[0])
with rigth_res:
st.write("# TruLens evaluation")
print(true_lens_result["app_json"])
st.dataframe(true_lens_result)
left_res, rigth_res = st.columns([1, 1])

if graph_result[0]:
json_str = json.dumps(graph_result[0], indent=4)
df = pd.DataFrame(graph_result[0])
with left_res:
st.write("# Answer")
st.write(graph_result[0])
with rigth_res:
st.write("# TruLens evaluation")
print(true_lens_result["app_json"])
st.dataframe(true_lens_result)

st.download_button(
label="Download JSON",
data=json_str,
file_name="scraped_data.json",
mime="application/json"
)
if graph_result[0]:
json_str = json.dumps(graph_result[0], indent=4)
df = pd.DataFrame(graph_result[0])

csv = df.to_csv(index=False)
st.download_button(
label="Download CSV",
data=csv,
file_name="scraped_data.csv",
mime="text/csv"
)
st.download_button(
label="Download JSON",
data=json_str,
file_name="scraped_data.json",
mime="application/json"
)

csv = df.to_csv(index=False)
st.download_button(
label="Download CSV",
data=csv,
file_name="scraped_data.csv",
mime="text/csv"
)

left_co2, *_, cent_co2, last_co2 = st.columns([1]*18)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pandas==2.0.3
scrapegraphai==0.0.6
scrapegraphai==0.0.7
28 changes: 28 additions & 0 deletions text_to_speech.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Basic example of scraping pipeline using SpeechSummaryGraph
"""

from scrapegraphai.graphs import SpeechSummaryGraph

def text_to_speech(key:str, prompt:str, url:str):
"""
Given a text it reads after the prompt
Args:
- url (str): url to scrape
- prompt(str): prompt to do
- key(str) openaikey
"""


llm_config = {
"api_key": key
}

# Save the audio to a file
audio_file = "audio_result.mp3"
speech_summary_graph = SpeechSummaryGraph(prompt,
url, llm_config,
audio_file)

return speech_summary_graph.run()

0 comments on commit c18d018

Please sign in to comment.