Download app.py from Pezh/io2: direct link, hf CLI and curl.
- Browser
- Download file 4.05 kB
-
https://huggingface.co/spaces/Pezh/io2/resolve/main/app.py
- Command line
-
hf download hf://spaces/Pezh/io2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Pezh/io2/resolve/main/app.py
4.05 kB
| import streamlit as st | |
| import sys | |
| from PyQt5.QtWidgets import ( | |
| QApplication, | |
| QMainWindow, | |
| QWidget, | |
| QVBoxLayout, | |
| QLineEdit, | |
| QPushButton, | |
| QLabel, | |
| QFileDialog | |
| ) | |
| from PyQt5.QtGui import QPixmap | |
| from PyQt5.QtCore import Qt | |
| import google.generativeai as genai | |
| genai.configure(api_key="AIzaSyBd36RWeqDpLur3E7TTlX3wnyIh_rdhsU8") | |
| # Set up the model | |
| generation_config = { | |
| "temperature": 0.9, | |
| "top_p": 1, | |
| "top_k": 1, | |
| "max_output_tokens": 2048, | |
| } | |
| safety_settings = [ | |
| { | |
| "category": "HARM_CATEGORY_HARASSMENT", | |
| "threshold": "BLOCK_MEDIUM_AND_ABOVE" | |
| }, | |
| { | |
| "category": "HARM_CATEGORY_HATE_SPEECH", | |
| "threshold": "BLOCK_MEDIUM_AND_ABOVE" | |
| }, | |
| { | |
| "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", | |
| "threshold": "BLOCK_MEDIUM_AND_ABOVE" | |
| }, | |
| { | |
| "category": "HARM_CATEGORY_DANGEROUS_CONTENT", | |
| "threshold": "BLOCK_MEDIUM_AND_ABOVE" | |
| }, | |
| ] | |
| #text_input = st.text_input('Enter some text') | |
| model = genai.GenerativeModel(model_name="gemini-pro", | |
| generation_config=generation_config, | |
| safety_settings=safety_settings) | |
| prompt_parts = ['what is google?'] | |
| response = model.generate_content(prompt_parts) | |
| class ExampleApp(QMainWindow): | |
| def __init__(self): | |
| super().__init__() | |
| self.setWindowTitle('Simple PyQt5 App') | |
| self.setGeometry(100, 100, 800, 600) | |
| central_widget = QWidget(self) | |
| self.setCentralWidget(central_widget) | |
| # Layout | |
| layout = QVBoxLayout() | |
| central_widget.setLayout(layout) | |
| # Text input with placeholder | |
| self.text_input = QLineEdit(self) | |
| self.text_input.setPlaceholderText('how can i kiss you') | |
| layout.addWidget(self.text_input) | |
| # File input that accepts images and videos | |
| self.file_input = QPushButton('Choose image or video', self) | |
| self.file_input.clicked.connect(self.open_file) | |
| layout.addWidget(self.file_input) | |
| # Placeholder for the image | |
| self.image_label = QLabel(self) | |
| self.image_label.setAlignment(Qt.AlignCenter) | |
| layout.addWidget(self.image_label) | |
| # Output Text input | |
| self.output_text_input = QLineEdit(self) | |
| layout.addWidget(self.output_text_input) | |
| # Multiply button | |
| multiply_btn = QPushButton('Multiply by 2', self) | |
| multiply_btn.clicked.connect(self.hops)#multiply_by_two) | |
| layout.addWidget(multiply_btn) | |
| # Clean button | |
| clean_btn = QPushButton('Clean', self) | |
| clean_btn.clicked.connect(self.clean_fields) | |
| layout.addWidget(clean_btn) | |
| def open_file(self): | |
| file_name, _ = QFileDialog.getOpenFileName(self, "Open File", "", "Image Files (*.png *.jpg *.jpeg);;Video Files (*.mp4 *.avi)") | |
| if file_name: | |
| if any(file_name.lower().endswith(ext) for ext in ['.png', '.jpg', '.jpeg']): # Check if it's an image | |
| pixmap = QPixmap(file_name) | |
| self.image_label.setPixmap(pixmap.scaled(self.image_label.size(), Qt.KeepAspectRatio)) | |
| # You can handle video files differently if required | |
| def multiply_by_two(self): | |
| try: | |
| # Multiply the number by 2 | |
| number = float(self.text_input.text()) | |
| result = number * 2 | |
| self.output_text_input.setText(str(result)) | |
| except ValueError: | |
| self.output_text_input.setText("Please enter a valid number") | |
| def hops(self): | |
| self.output_text_input.setText(str(response)) | |
| def clean_fields(self): | |
| # Clean the text fields and image label | |
| self.text_input.clear() | |
| self.output_text_input.clear() | |
| self.image_label.clear() | |
| def pty(): | |
| #if __name__ == '__main__': | |
| app = QApplication(sys.argv) | |
| ex = ExampleApp() | |
| ex.show() | |
| sys.exit(app.exec_()) | |
| if st.button('Start Bot'): | |
| st.write('Bot is starting...') | |
| #run_bot_thread() | |
| pty() |