File size: 1,941 Bytes
ca165c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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)}")