Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Basic ques_ans.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python
# coding: utf-8

# In[6]:


get_ipython().system('pip install openai')


# In[8]:


import openai
api_key = "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"
openai.api_key = api_key
que=input("Please Write Your Question:")

response = openai.Completion.create(
engine="text-davinci-002",
prompt=que,
max_tokens=2000 # Adjust this value to control the response length
)

# Extract the generated answer
ans = response.choices[0].text


print("Q:", que)
print("Ans:", ans)


# In[ ]:




54 changes: 54 additions & 0 deletions Gives youtube video as resources for search result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python
# coding: utf-8

# In[4]:


import requests

# Replace with your actual YouTube Data API key and endpoint
api_key = 'AIzaSyBhTt5SFFN7MgyI-Qt2t8XtX2AHQ0mi_wc'
api_endpoint = 'https://www.googleapis.com/youtube/v3/'

# Get user input for the search query and the number of results
search_query = input("Enter your search query: ")
max_results = int(input("Enter the maximum number of results to retrieve: "))

# Define parameters for your YouTube API request
params = {
'part': 'snippet', # Specify the data you want to retrieve
'q': search_query, # User-provided search query
'maxResults': max_results, # User-provided maximum number of results
'key': api_key, # Include your API key
}

try:
response = requests.get(f'{api_endpoint}search', params=params)

if response.status_code == 200:
data = response.json()
if 'items' in data:
print("Search Results:")
for item in data['items']:
if item['id']['kind'] == 'youtube#video':
video_title = item['snippet']['title']
video_id = item['id']['videoId']
video_url = f"https://www.youtube.com/watch?v={video_id}"
print(f"Title: {video_title}")
print(f"Video URL: {video_url}")
else:
print(f"Skipping non-video item: {item['snippet']['title']}")
else:
print("No results found.")
else:
print(f"API request failed with status code {response.status_code}")

except Exception as e:
print(f"An error occurred: {str(e)}")


# In[ ]:




40 changes: 40 additions & 0 deletions Question generator based on any topic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
"""Untitled9.ipynb

Automatically generated by Colaboratory.

Original file is located at
https://colab.research.google.com/drive/1hkaavvCZV1nDS2_uOuQMh30otjWfIlSL
"""

!pip install openai

import openai


api_key = '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'


openai.api_key = api_key


def generate_questions(prompt, num_questions=5, max_tokens=50):
response = openai.Completion.create(
engine="text-davinci-002", # Choose an appropriate engine
prompt=prompt,
max_tokens=max_tokens, # Adjust the max tokens as needed
n=num_questions # Fixed number of questions to generate
)

generated_questions = [question['text'].strip() for question in response.choices]
return generated_questions

user_prompt = input("Enter the text for which you want to generate questions: ")

# Generate questions based on user input (fixed number of 2 questions)
generated_questions = generate_questions(user_prompt)

# Print the generated questions
print("\nGenerated Questions:")
for i, question in enumerate(generated_questions):
print(f"{i + 1}) {question}")
Loading