| |
| import streamlit as st |
| import requests |
| import csv |
| from datetime import datetime |
| import subprocess |
|
|
| |
| st.title("Conversation Generator") |
|
|
| @st.cache(allow_output_mutation=True) |
| def generate_conversation(prompt): |
| try: |
| |
| prompt_variation = prompt + str(hash(prompt))[:3] |
|
|
| |
| response = requests.post('https://api-inference.huggingface.co/models/facebook/blenderbot-400M-distill', json={ |
| "inputs": prompt_variation, |
| "options": {"temperature": 0.8} |
| }) |
|
|
| 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 |
|
|
| |
| with open("index.html", "r", encoding="utf-8") as html_file: |
| index_html_content = html_file.read() |
|
|
| |
| st.markdown(index_html_content, unsafe_allow_html=True) |
|
|
| |
| 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)}") |
|
|