ab / app.py
theapps's picture
Upload 36 files
ca165c7 verified
# streamlit_app.py
import streamlit as st
import requests
import csv
from datetime import datetime
import subprocess
# Define Streamlit app
st.title("Conversation Generator")
@st.cache(allow_output_mutation=True)
def generate_conversation(prompt):
try:
# Introduce slight variations in the prompt
prompt_variation = prompt + str(hash(prompt))[:3]
# Adjust temperature for more diverse responses
response = requests.post('https://api-inference.huggingface.co/models/facebook/blenderbot-400M-distill', json={
"inputs": prompt_variation,
"options": {"temperature": 0.8} # Adjust as needed
})
conversation = response.json()["generated_text"]
return conversation
except Exception as e:
return f"Error: {str(e)}"
def save_to_csv(prompt, conversation):
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
filename = f"info.csv"
with open(filename, mode='w', newline='', encoding='utf-8') as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(['Prompt', 'Generated Conversation'])
csv_writer.writerow([prompt, conversation])
return filename
# Load index.html content
with open("index.html", "r", encoding="utf-8") as html_file:
index_html_content = html_file.read()
# Embed HTML content in Streamlit
st.markdown(index_html_content, unsafe_allow_html=True)
# Define Streamlit UI
prompt = st.text_area("Enter prompt:")
if st.button("Generate and Display"):
conversation = generate_conversation(prompt)
csv_filename = save_to_csv(prompt, conversation)
st.write("Generated Conversation:")
st.write(conversation)
st.write("CSV file saved:", csv_filename)
if st.button("Run AAMain.py"):
try:
subprocess.run(["python", "AAmain.py"])
st.success("AAmain.py process started successfully.")
except Exception as e:
st.error(f"Error: {str(e)}")